I have a function Person (I use ES5 for this example)
function Person(name) {
this.name = name
}
Person.prototype.printName = function() {
console.log(this.name)
}
As I understand, my newly created object ".proto" reference should be equal to Person.prototype (like new operator does). I use Object.create to set appropriate proto. How should I pass additional arguments to my newly created instance so that my 'TestName' argument should be equal to this.name
Create instance function itself:
function createInstance(constructor, ...args) {
let instance = Object.create(constructor.prototype)
instance.call(constructor, args)
return instance
}
let instance = createInstance(Person, 'TestName')
console.log(instance)