Created
March 20, 2017 17:06
-
-
Save topicus/6aeef171f527eac76dc03fe4627495cf to your computer and use it in GitHub Desktop.
Difference between function vs function constructors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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