Skip to content

Instantly share code, notes, and snippets.

@mjhoy
Created March 24, 2014 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjhoy/9738680 to your computer and use it in GitHub Desktop.
Save mjhoy/9738680 to your computer and use it in GitHub Desktop.
js: new is problematic
function K() {
this.za = "ze";
};
console.log(new K()); // => K { za: "ze" }
K.D = function() {
this.la = "le";
};
console.log(new K.D()); // => K.D { la: "le" }
console.log(new K.D); // => K.D { la: "le" }
K.C = function () {
return function Y() {
this.grr = true;
};
};
console.log(new K.C); // => function Y() { ... } whoops!
console.log(new K.C()); // => function Y() { ... } whoops!
// here's what we wanted
console.log(new (K.C())); // => Y { grr: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment