Created
November 22, 2014 13:04
-
-
Save alessioalex/79247604500a8b04e20a to your computer and use it in GitHub Desktop.
calling-without-new.js
This file contains 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 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