www.webdeveloper.com
Results 1 to 4 of 4

Thread: what do this mean ?

  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,407
    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
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  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,407
    I over simplified but the essence of it is a TRUE or FALSE situation.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

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