Skip to content

Instantly share code, notes, and snippets.

@diegogurgel
Created November 10, 2017 17:19
Show Gist options
  • Save diegogurgel/5198f995c79ce27fc6716ea341873500 to your computer and use it in GitHub Desktop.
Save diegogurgel/5198f995c79ce27fc6716ea341873500 to your computer and use it in GitHub Desktop.
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