Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Created November 22, 2014 13:04
Show Gist options
  • Save alessioalex/79247604500a8b04e20a to your computer and use it in GitHub Desktop.
Save alessioalex/79247604500a8b04e20a to your computer and use it in GitHub Desktop.
calling-without-new.js
function Student(name, age, university) {
if (!(this instanceof Student)) {
return new Student(name, age, university);
}
// #1 - duplicate code from Person constructor
//Person.call(this, name, age);
this.university = university;
}
var junior2 = Student('John', 18, 'MIT');
console.log(junior2.getInfoCard());
//console.log(junior2 instanceof Person);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment