Skip to content

Instantly share code, notes, and snippets.

@IdahoEv
Created March 23, 2018 18:23
Show Gist options
  • Save IdahoEv/13796f2a2d6dad8fcf64dc87e617b324 to your computer and use it in GitHub Desktop.
Save IdahoEv/13796f2a2d6dad8fcf64dc87e617b324 to your computer and use it in GitHub Desktop.
// a function is just a function. By default it has no 'this' and returns nothing
function myFunction() {
this.value = 5;
}
// if I call it, I get nothing back
var obj1 = myFunction(); // obj1 is undefined
// if I call it with 'new', a new empty object is assigned to 'this' and returned to me afterwards
var obj2 = new myFunction(); // obj2 is { value: 5 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment