Created
June 17, 2024 20:28
-
-
Save woshichuanqilz/5ae1e17b408a8685f7c66bd83d0ee46a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 创建一个人物对象 | |
const person = { | |
name: 'John', | |
age: 30, | |
greet: function() { | |
console.log(`你好,我的名字是${this.name},我今年${this.age}岁。`); | |
} | |
}; | |
// 创建一个带有绑定执行上下文的新函数 | |
const greetFunction = person.greet.bind(person); | |
// 调用绑定的函数 | |
greetFunction(); // 输出:你好,我的名字是John,我今年30岁。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment