Created
March 25, 2010 12:15
-
-
Save bga/343478 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* MODIFY PROTOTYPE */ | |
var _fn=function(){}; | |
_fn.prototype.a=1; | |
var v=new _fn(); | |
alert(v.a === 1); /* true */ | |
alert(v.constructor === _fn); /* true */ | |
/* REPLACE PROTOTYPE */ | |
var _fn=function(){}; | |
_fn.prototype={a:1}; | |
var v=new _fn(); | |
alert(v.a === 1); /* true */ | |
alert(v.constructor === _fn); /* false in ie; true in other browsers */ | |
/* but */ | |
alert(v.constructor === Object.prototype); /* true in ie. ie set 'constructor' property eq Object if 'prototype' replaced */ | |
/* REPLACE PROTOTYPE WITH FIXING BUG OF IE */ | |
var _fn=function(){}; | |
_fn.prototype={a:1}; | |
var v=new _fn(); | |
v.constructor=_fn; /* set 'constructor' property by hands */ | |
alert(v.a === 1); /* true */ | |
alert(v.constructor === _fn); /* now true in all browsers */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment