Unfortunately, there is no way to add a property to only certain functions through a prototype chain. Functions have one object in the prototype chain, which is equal Function.prototype. It is not possible to create functions that have other [[Prototype]]s.
, , :
function Foo (name) = {
val = name;
ret = function () { return val; }
ret.set = function (v) { return val = v; }
return ret;
}
. prototype
Function.prototype.set = function (v) { return this.val = v; };
function Foo (name){
ret = function () { return this.val; }
ret.val = name;
return ret;
}
var f = new Foo('myfunc');
f.set('myval');
console.log(f.val);
, , / set. Prototypes , .