Skip to content

Instantly share code, notes, and snippets.

@topicus
Created March 20, 2017 17:06
Show Gist options
  • Save topicus/6aeef171f527eac76dc03fe4627495cf to your computer and use it in GitHub Desktop.
Save topicus/6aeef171f527eac76dc03fe4627495cf to your computer and use it in GitHub Desktop.
Difference between function vs function constructors
function LikeButton(id) {
this.id = id;
}
// In this case "this" will point to btn. You can read the function like this:
// function LikeButton(id) {
// btn.id = id;
// return btn;
// }
let btn = new LikeButton('like-button');
// In this case "this" will point either to undefined in strict mode
// or window in quirks mode.
let btn = LikeButton('like-button');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment