suppose that I have this function
function test() {
console.log('test');
}
test.property = 'testProperty';
And I want to extend the function object by doing
var extend = Object.create(test);
Well, the property from the function was correctly propagated
console.log(extend.property); // testProperty
But I can't extend the function test itself, nor access it via extend()
extend(); // TypeError: ext is not a function
Okay, I can just create new function with modified __proto__
function extend() {
console.log('extended!');
}
extend.__proto__ = test;
extend(); // extended!
console.log(extend.property); // testProperty
But, editing __proto__
property is a slow operation, as per this Javascript MDN Documentation. So, is there any function like Object.create()
that can I use to implement this kind of operation? Thanks.