const person = {
name: "Mike",
country: "New Zealand"
}
function personUpdate(name, country) {
this.name = name
this.country = country
}
personUpdate.bind(person)
personUpdate('Tony', 'Chile')
Warum funktioniert das nicht? person
hat immer noch die Originaleigenschaften 'Mike' und 'New Zealand'. Warum nicht personUpdate.bind(person)
Ich möchte es so machen, dass jeder Anruf an personUpdate
die this
bezieht sich auf das person
Objekt (und ohne new
verwenden).JavaScript-Bindungsfunktion an ein Objekt
var boundPersonUpdate = personUpdate.bind (Person); boundPersonUpdate ('Tony', 'Chile'); – kangsu