Показать сообщение отдельно
  #3 (permalink)  
Старый 17.03.2020, 20:21
Аватар для SuperZen
Профессор
Отправить личное сообщение для SuperZen Посмотреть профиль Найти все сообщения от SuperZen
 
Регистрация: 08.11.2017
Сообщений: 642

взял здесь - https://developer.mozilla.org/en-US/...rototype_chain
...
Performance
The lookup time for properties that are high up on the prototype chain can have a negative impact on the performance, and this may be significant in the code where performance is critical. Additionally, trying to access nonexistent properties will always traverse the full prototype chain.
...
Bad practice: Extension of native prototypes
One misfeature that is often used is to extend Object.prototype or one of the other built-in prototypes.

This technique is called monkey patching and breaks encapsulation. While used by popular frameworks such as Prototype.js, there is still no good reason for cluttering built-in types with additional non-standard functionality.


...
In conclusion
It is essential to understand the prototypal inheritance model before writing complex code that makes use of it. Also, be aware of the length of the prototype chains in your code and break them up if necessary to avoid possible performance problems. Further, the native prototypes should never be extended unless it is for the sake of compatibility with newer JavaScript features.

...

const obj = { a: 1 }
function myFoo() {
  console.log(this.a)
}
const myFooInstance = myFoo.bind(obj)
myFooInstance()
myFoo.call(obj)
myFoo.apply(obj)


) не ответ на конкретный вопрос...
Ответить с цитированием