dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: what do this mean ?

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    7

    what do this mean ?

    Code:
    function getStyle( elem, name ) {
        if (elem.style[name])
            return elem.style[name];
        else if (elem.currentStyle)
            return elem.currentStyle[name];
        else if (document.defaultView && document.defaultView.getComputedStyle) {
            name = name.replace(/([A-Z])/g,"-$1");
            name = name.toLowerCase();
            var s = document.defaultView.getComputedStyle(elem,"");
            return s && s.getPropertyValue(name);
        } else
            return null;
    }
    function getStyle(elem,name){ 
    if(elem.style[name]){ 
    return elem.style[name]; 
    }else if(elem.currentStyle){ 
    return elem.currentStyle[name]; 
    }else if(document.defaultView && document.defaultView.getComputedStyle){ 
    name = name.replace(/([A-Z])/g,"-$1"); 
    name = name.toLowerCase(); 
    
    var s = document.defaultView.getComputedStyle(elem,""); 
    return s && s.getPropertyValue(name); 
    }else{ 
    return null; 
    } 
    }
    i dont understand return s && s.getPropertyValue(name) , what does it return ?

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,968
    The && is javascript for AND which is a boolean expression that tests two values and returns a value.

    X = 1 && 1;

    y = 1 && 0;


    x will be TRUE where as y will be FALSE

    so returning s && s.getPropertyValue(name); is going to either return a TRUE or a FALSE value
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Jul 2011
    Posts
    131
    Code:
    return s && s.getPropertyValue(name);
    will not return TRUE or FALSE.
    This mean that function will return s.getPropertyValue(name) ONLY if s is set.
    In other words function will return s.getPropertyValue(name) if s in not null, undefined, 0, false, etc - any of "falsy" value that is converted to false.

    This is done to avoid exception.
    For example you know that function getComputedStyle returns some object or null.
    So after writing return s && s.getPropertyValue(name); you are sure that function getPropertyValue will be called only if s is a valid object and not null.

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,968
    I over simplified but the essence of it is a TRUE or FALSE situation.
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles