-
-
Save alloyking/6981728 to your computer and use it in GitHub Desktop.
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
/** | |
* Constructor Invocation Pattern | |
* Requires use of the "new" keyword, allows for inheritance, but no information hiding | |
* The Functional Pattern is recommended over the Constructor Invocation Pattern | |
*/ | |
// create a constructor function for the base class | |
var Person = function (spec) { | |
// pseudo-class vars | |
spec.name = spec.name || ''; | |
this.name = spec.name; | |
}; | |
// create a constructor function for the child class | |
var Employee = function (spec) { | |
// call parent constructor | |
Person.call(this, spec); | |
// pseudo-class vars | |
spec.employeeId = spec.employeeId || 0; | |
this.employeeId = spec.employeeId; | |
}; | |
var curt = new Employee({name: 'Curtis Branum', employeeId: 207}); | |
console.log(curt); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment