Created
January 2, 2012 04:44
-
-
Save sofish/1549380 to your computer and use it in GitHub Desktop.
在 js 实例化的时候去 new
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
function Call(name){ | |
if(!(this instanceof Call)) return new Call(name); | |
this.name = name; | |
this.hello = function(){ | |
alert('hello, ' + this.name); | |
} | |
} | |
var hi = Call('sofish'); // 有没有 new 都无所谓 | |
alert(hi.name); | |
hi.hello(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment