Skip to content

Instantly share code, notes, and snippets.

@honjo2
Created October 13, 2010 09:51
Show Gist options
  • Save honjo2/623769 to your computer and use it in GitHub Desktop.
Save honjo2/623769 to your computer and use it in GitHub Desktop.
[js] newし忘れても問題ない擬似クラス
function Waffle() {
if (!(this instanceof arguments.callee)) {
return new arguments.callee();
}
this.tastes = "yummy";
}
Waffle.prototype.wantAnother = true;
var first = new Waffle();
var second = Waffle();
console.log(first.tastes); // yummy
console.log(second.tastes); // yummy
console.log(first.wantAnother); // true
console.log(second.wantAnother); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment