Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Created February 3, 2019 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitfishxyz/1eff4772a76d42f885b741f3b9a9978d to your computer and use it in GitHub Desktop.
Save bitfishxyz/1eff4772a76d42f885b741f3b9a9978d to your computer and use it in GitHub Desktop.
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