Skip to content

Instantly share code, notes, and snippets.

@fxxkscript
Created December 19, 2012 02:29
Show Gist options
  • Save fxxkscript/4333865 to your computer and use it in GitHub Desktop.
Save fxxkscript/4333865 to your computer and use it in GitHub Desktop.
自调用构造函数
//自调用构造函数
function Waffle() {
if (!(this instanceof Waffle)) {
return new Waffle();
}
this.tastes = "yummy";
}
var first = new Waffle(),
second = Waffle();
console.log(first.tastes);
console.log(second.tastes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment