Answer the question
In order to leave comments, you need to log in
When borrowing a method, does the object live or be sawn out?
...
arguments.join = [].join;
...
Answer the question
In order to leave comments, you need to log in
Firstly, you do not extend the method, but get a link to it. Secondly, the reference to the method, in your case, is not in the object itself, but is a property of the prototype. Third, in JavaScript , objects are deleted based on the reachability principle. If there is no reference to the object, then the memory occupied by it will be cleared as soon as possible. If there are references to the object, then this is not a guarantee that the memory will not be cleared.
For example:
let foo = {};
let bar = {};
foo.barLink = bar;
bar.fooLink = foo;
foo = bar = null;
class Person {
constructor(name) {
this.name = name;
}
printName() {
console.log(this.name);
}
}
let john = new Person('John');
const obj = {};
obj.printJohnName = john.printName.bind(john);
john = null;
obj.printJohnName(); // 'John'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question