const user = {
name: "Praveen",
videos: ["html", "css", "js"],
greet() {
console.log(`welcome ${this.name}`);
const getVideos = () => {
console.log(`You have ${this.videos.length} videos`);
};
getVideos();
},
};
user.greet();
我可以访问videos.length上面代码中的值(我使用了箭头函数),但我无法访问videos.length下面代码中的值:
const user = {
name: "Praveen",
videos: ["html", "css", "js"],
greet() {
console.log(`welcome ${this.name}`);
const getVideos = function () {
console.log(`You have ${this.videos.length} videos`);
};
getVideos();
},
};
user.greet();
茅侃侃
阿晨1998
九州编程
相关分类