ruanyf / es6tutorial

《ECMAScript 6入门》是一本开源的 JavaScript 语言教程,全面介绍 ECMAScript 6 新增的语法特性。

Home Page:http://es6.ruanyifeng.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Class的基本语法章节书写错误

idigan opened this issue · comments

class A {  
  #foo = 0; 
  static test(obj) {
    console.log(#foo in obj);
  }
}
const a = new A();

const o1 = Object.create(a);
A.test(o1) // false
A.test(o1.__proto__) // true

const o2 = {};
Object.setPrototypeOf(o2, A);
A.test(o2) // false
A.test(o2.__proto__) // true

语句Object.setPrototypeOf(o2, A)中的字母A应该为 a

这样A.test(o2.__proto__)结果才为 true

谢谢指出,已经更正。