-
数组遍历,for in 会遍历数组对象原型链上的属性,不保存顺序查看全部
-
枚举,object.propertyIsEnumerable('property')查看全部
-
object.configurable查看全部
-
模块化查看全部
-
defineProperty(ES5)查看全部
-
抽象类查看全部
-
对象标签,序列化,结构,方法查看全部
-
链式调用查看全部
-
调用子类方法查看全部
-
模拟重载查看全部
-
实现继承的方式: if(! Object.create){ Object.create = function(proto){ function F(){} F.prototype = proto; return new F(); }; } Student.prototype = Object.create(Person.prototype); Student.prototype.constructor = Student;查看全部
-
修改内置构造器的 prototype Object.prototype.x = 1; 在 for in 遍历时,会遍历到 x Object.defindProperty(Object.prototype, 'x', {value: 1, writable: true}); 在 for in 遍历时,则不会遍历到 x 原型链上的 prototype 属性值: 可配置(configuarable)、可枚举(enumerable)、可写(writable) 这些属性都默认都为 false Object.hasOwnProperty(x) 可以判断某个属性是否属于对象本身的属性(用来排除原型链上的属性干扰)查看全部
-
动态改变 prototype查看全部
-
再谈原型链 查看对象原型的方法: var obj = {x: 1, y: 2}; 1. 通过非标准的 obj.__proto__ 2. 通过 ECMA5 的 Object.getPrototypeOf(obj) 原型链上的特殊情况: 1. Object.create(null) 创建的对象的原型 __proto__ 为 undefined 2. 对象 obj 进行 var nObj = obj.bind(null) 操作后,nObj.prototype 为 undefined查看全部
-
Javascript 如何实现对“类”的继承 function Person(name, age){ this.name = name; this.age = age; } Person.prototype.hi = function(){ console.log('Hi,my name is' + this.name + ',I'm' + this.age + 'years old'); } function Student(name, age, course){ // 通过 Person.call 继承 Person 的属性 Person.call(this, name, age); this.course = course; } // 通过 Object.create(Person.prototype) 继承 Person.prototype 上的方法 Student.prototype = Object.create(Person.prototype); Student.prototype.constructor = Student; Object.create(param) 的作用: 创建一个空对象,并将该对象的原型 __proto__ 指向其参数 因此,用作继承时,Object.create 的参数通常为父类的构造器的 prototype 属性查看全部
举报
0/150
提交
取消