2022-01-06 18:14:37 +08:00

33 lines
661 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 逆向中偶有见到hook 常用
// apply,重定义指定对象。参数数组传递
// output
let person = {
fullInfo: function (city, country) {
return this.name + "-" + this.age + "-" + country + "-" + city
}
};
let person1 = {
name: "jor",
age: "25"
};
console.log(person.fullInfo.apply(person1, ["osle", "norway"]));
// call 重定义指定对象,可以直接传参
let person2 = {
fullInfo: function (city, country) {
return this.name + "-" + this.age + "-" + country + "-" + city;
}
};
let person3 = {
name: "jor",
age: "25"
};
console.log(person.fullInfo.call(person3, "Oslo", "Norway"));