Created
February 3, 2019 05:25
-
-
Save bitfishxyz/1eff4772a76d42f885b741f3b9a9978d 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
function newOperator(constructor, args) { | |
var new_created_obj = Object.create(constructor.prototype) | |
constructor.apply(new_created_obj, args) | |
return new_created_obj | |
} | |
function Person(name, age) { | |
this.name = name | |
} | |
Person.prototype.getName = function (){ | |
return this.name | |
} | |
var p1 = new Person('Bob') | |
console.log(p1) | |
console.log(p1.getName()) | |
var p2 = newOperator(Person, ['Bob']) | |
console.log(p2) | |
console.log(p2.getName()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment