Created
November 10, 2017 17:19
-
-
Save diegogurgel/5198f995c79ce27fc6716ea341873500 to your computer and use it in GitHub Desktop.
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
var Foo = function () { | |
if(this instanceof Foo){ | |
this.a = true; | |
this.b = 'hello'; | |
this.c = 5; | |
} else { | |
return new Foo(); | |
} | |
}; | |
Foo.prototype.log = function(text) { | |
console.log('text is ' + text); | |
} | |
// --------------------------------- | |
var bar = new Foo(); | |
var bar1 = Foo(); | |
console.log(bar.b === 'hello'); | |
console.log(bar1.b === 'hello'); | |
console.log(bar instanceof Foo); | |
console.log(bar1 instanceof Foo); | |
bar.log('123'); | |
bar1.log('123'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment