SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how the browser understand this code

    i wrote like this:
    Code:
    var a = function b(){
    	return b;
    };
    alert(a() === a );
    and ie6~ie8 return false , ie9 chrome ff return true.
    how to explain it?
    and
    Code:
    var a = function b(){
    };
    alert( typeof b );
    b is undefined in most of browser but is function in ie6~ie8,
    that's why?
    thx

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by henry42 View Post
    i wrote like this:
    Code:
    var a = function b(){
    	return b;
    };
    alert(a() === a );
    and ie6~ie8 return false , ie9 chrome ff return true.
    how to explain it?
    Internet Explorer doesn't use JavaScript. Instead, it uses their own creation called JScript which is supposed to be the same, but has some bugs in it.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Internet Explorer doesn't use JavaScript. Instead, it uses their own creation called JScript which is supposed to be the same, but has some bugs in it.
    thank u very much

  4. #4
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You need to be careful what you are comparing.

    var a = function b(){ return typeof b; };
    alert(a())
    returns function in all browsers
    //
    alert(typeof a)
    returns function in all browsers
    //
    alert(a() === typeof a)
    returns true in all browsers.

    However,
    var a = function b() { return b; };
    returns function b() { return b; }

    alert(a() === a ); fails in IE, probably because the layout of the two functions is not exactly the same. You can see this if you look at the return info.


Bookmarks

Posting Permissions

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