Discuss / JavaScript / 接着例子继续加几个测试,最后一句为什么出错

接着例子继续加几个测试,最后一句为什么出错

Topic source

Otoboku_

#1 Created at ... [Delete] [Delete and Lock User]

var xiaoming = createStudent('小明'); xiaoming.run(); // 小明 is running... xiaoming.proto === Student; // true

console.log(typeof xiaoming);//object //出错 console.log(xiaoming instanceof Student);

Otoboku_

#2 Created at ... [Delete] [Delete and Lock User]

而且不同的建立方式在prototype,proto值还不一样.

var xiaoming = Object.create(Student); //undefined console.log(xiaoming.prototype); //{ name: 'Robot', height: 1.2, run: [Function: run] } console.log(xiaoming.proto);

xiaoming = new Object(Student); //undefined console.log(xiaoming.prototype); //{} console.log(xiaoming.proto);


  • 1

Reply