
原型
文章平均质量分 77
lihefei_coder
这个作者很懒,什么都没留下…
展开
-
JavaScript原型详解
function Person(name) { this.name = name;}Person.prototype.fn = function() { console.log(this.name);};var person = new Person('小明');person.constructor === Person; //trueperson.__prot...原创 2019-05-14 21:09:21 · 312 阅读 · 0 评论 -
javascript原型链剖析
剖析p.age属性的获取过程,为何最终是undefined?class Person { constructor() { this.name = 'zhangshan'; } say(str) { console.log(str); }}var p = new Person();console.log(p.age); //undefined第一步:在p对象自身找,...原创 2019-05-15 21:57:48 · 226 阅读 · 0 评论 -
javascript核心(对象、原型、继承、作用域、闭包、this)
原型继承新建一个对象,如果没有明确指定原型,那么它的原型对象将默认指向Object.protorype实现继承let a = { x: 1};a.__proto__ === Object.prototype; // true手动为一个对象指定原型,下面的例子把a对象指定为b对象的原型,实现了继承let a = { x: 1};let b = { y: 2, ...原创 2019-05-27 15:18:34 · 443 阅读 · 0 评论 -
ES6 class中consructor与super的理解
首先,ES6 的 class 属于一种“语法糖”,所以只是写法更加优雅,更加像面对对象的编程,其思想和 ES5 是一致的。function Point(x, y) { this.x = x; this.y = y;}Point.prototype.toString = function() { return '(' + this.x + ',' + this.y + ')';...转载 2019-05-27 20:00:41 · 244 阅读 · 0 评论