class Dog {
#sound = 'Woof! Woof!'; // this is private
makeSound() {
console.log( this.#sound );
}
}
// create instance
const tommy = new Dog();
tommy.makeSound() // Woof! Woof!
//console.log( tommy.#sound ); // SyntaxError
JS私有类字段
最新推荐文章于 2024-06-05 21:39:01 发布