Answer the question
In order to leave comments, you need to log in
How to organize inheritance in JavaScript built-in classes so that methods are called up the chain?
Let's say the any() method is defined for the built-in Object and Array class through the prototype property:
Object.defineProperty(Object.prototype, "any", {
value: function(){
console.log("object.any");
return this;
} // function
,enumerable :false
});
Array.prototype.any = function(){
console.log("array.any");
return this;
}; // any
[].any();
Answer the question
In order to leave comments, you need to log in
Object.prototype.any = function() {
console.log('object.any');
return this;
};
Array.prototype.any = function() {
console.log('array.any');
return this;
};
// или -----------------------------------------------
Object.defineProperty(Object.prototype, 'any', {
value: function() {
console.log('object.any');
return this;
},
enumerable: false,
writable: true // for assigment operation (=) support
});
Array.prototype.any = function() {
console.log('array.any');
return this;
};
// или -----------------------------------------------
Object.defineProperty(Object.prototype, 'any', {
value: function() {
console.log('object.any');
return this;
},
enumerable: false
});
Object.defineProperty(Array.prototype, 'any', {
value: function() {
console.log('array.any');
return this;
},
enumerable: false
});
// ---------------------------------------------------
[].any(); // array.any
({}).any(); // object.any
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question