临时笔记
OOP:
1.1特性:继承、封装、多态、抽象
1.2获取对象原型 Object.getPrototypeOf(obj)
//构造类Person function Person(name,age){ this.name = name; this.age = age; } Person.prototype.hi = function(){ console.log(this.name + ' say hi.') } Person.prototype.LEGS = 2; //构造类Student function Student(name,age,className){ Person.call(this,name,age) this.className = className } Student.prototype = Object.create(Person.prototype); Student.prototype.construct = Student; Student.prototype.walk = function(){ console.log(this.name + ' is walking') } Student.prototype.hi = function(){ console.log(this.name + ' is saying') } //实例化Student var Sunbey = new Student('sunbey',18,'Grade 1 Class 2') //遍历Sunbey对象 for(var key in Sunbey){ var isTrue = Sunbey.hasOwnProperty(key) console.log('Is own property:' + isTrue + '; ' + key +': '+ Sunbey[key])
}