当前位置: 首页 > news >正文

17网一起做网店网站公司网页设计

17网一起做网店网站,公司网页设计,石家庄房价,网站建设方案包括基本术语 本文中,proto [[Prototype]] 原型链 基本思想: 构造函数生成的对象有一个指针(proto)指向构造函数的原型。如果将构造函数1的原型指向另一个构造函数2的实例,则构造函数1的实例__proto__.proto 指向了构…

基本术语

本文中,proto === [[Prototype]]

原型链

基本思想

  1. 构造函数生成的对象有一个指针(proto)指向构造函数的原型。
  2. 如果将构造函数1的原型指向另一个构造函数2的实例,则构造函数1的实例__proto__.proto 指向了构造函数2的原型。原型2和实例1之间构成了一条原型。
function Super() {};
function Sub() {};
Super.prototype.sayHi = function () { console.log('hi') };
Sub.prototype = new Super();const supInstance1 = new Sub();
supInstance1.sayHi(); // hi

缺点

  1. Sub.prototype.constructor 被改变。
  2. Sub.prototype = new Sub(),new的过程可能会有副作用。

盗用构造函数(经典继承)

基本思想

  1. 在new一个构造函数1的时候,通过在构造函数1中调用另一个构造函数2来实现继承。
  2. 通过调用构造函数2,将构造函数2中的实例属性复制到构造函数1的实例中。
function Car(wheels) {this.wheels = wheels;
}function ElectricCar(wheels, type) {Cat.call(this, wheels);this.type = type;
}

缺点

  1. 子类的实例不能访问父类原型上的方法。
  2. 必须在构造函数中定义方法,因此函数(构造函数1)不能重用。

组合继承(伪经典继承)

基本思想

  1. 将子类原型指向父类实例,通过原型链来实现子类继承父类原型上的方法。
  2. 通过盗用构造函数来继承实例的属性。
function Super(title) {this.title = title;
}
Super.prototype.sayHi = function () {console.log(this.title, " <- Super title");
};function Sub(superTitle, subTitle) {Super.call(this, superTitle);this.subTitlte = subTitle;
}Sub.prototype = new Super();const subInstance = new Sub("superTitle in instance", "subTitle in instance");subInstance.sayHi(); // ****subtitle in instance  <- this title****/* subInstance结构类型
**{"title": "superTitle in instance","subTitlte": "subTitle in instance",[[Prototype]]: Super
}--- 在[[Prototype]]:Super中
--- Super的结构类型{title: undefined,[[Prototype]]: Object,
}**
*/

缺点

  1. 在构造函数2的原型中,有无用变量title:undefined
  2. 在进行原型链的链接时,会执行new Super() 过程,如果构造函数Super是一个有副作用的函数,会有不可预知的问题。(两次调用Super函数)
  3. 子类的原型的constructor属性指向丢失。

原型式继承

基本思想

对象间构造原型链实现属性的共享。

实现

es5的Object.create函数

// 返回一个对象,对象.__proto__ 指向 o
function objectCreate(o) {function F() {};F.prototype = o;return new F();
}

寄生式继承

基本思想

  1. 通过工厂模式创建新对象,构造函数中通过原型式继承来获取目标对象的能力。
function createSub(originObject) {const newObject = Object.create(originObject);newObject.sayHi = function() { console.log('hi') };return newObject;
}const person = { name: '张三',friends: ['李四', '赵武', '甲一']
};const personA = createSub(person);
personA.sayHi();

优缺点

???感觉没有使用的场景

寄生式组合继承(目前比较完美的解决方案)

基本思想

  1. 重写子构造函数的原型,将构造函数原型的[[prototype]]指向从默认Object改为父构造函数的原型。实现原型属性的继承。
  2. 在子构造函数调用父构造函数,实现实例属性的复用。
function Super(name) {this.name = name;
}
Super.prototype.sayHi = function() { console.log(`hi this is super and name is ${this.name}`)};function Sub(name, age) {Super.call(this, name);this.age = age;
}Sub.prototype = Object.create(Super.prototype, {constructor: {value: Sub,enumerable: false,writable: true,configurable: true,},
});
// 这里同样可以用es6中的 setPrototypeOf 来设置原型链的链接Sub.prototype.sayAge = function () { console.log(`the age of ${this.name} is ${this.age}`); }const subInstance = new Sub('Sub instance', 12);subInstance.sayHi(); // hi this is super and name is Sub instance
subInstance.sayAge(); // **the age of Sub instance is 12**

优缺点

  1. 功能上没有缺点
  2. 实现起来冗长

es6的继承

extends关键字

es6的继承本质上是es5继承的语法糖。

// 可以实现和寄生式组合继承完全相同的效果
class Super {constructor(name) {this.name = name;}sayHi() {console.log(`hi this is super and name is ${this.name}`)}
}class Sub extends Super {constructor(name,  age) {super(name);this.age = age;}sayAge() {console.log(`the age of ${this.name} is ${this.age}`)}}const subInstance = new Sub('Sub instance', 12);subInstance.sayHi(); // hi this is super and name is Sub instance
subInstance.sayAge(); // **the age of Sub instance is 12**参考数据:
- [1] [你不知道的JavaScript]
- [2] [JavaScript高级程序设计]
- [3] [[mdn](https://developer.mozilla.org/)](https://developer.mozilla.org/)
http://www.qdjiajiao.com/news/12269.html

相关文章:

  • 网站的切图是谁来做西安优化外
  • 手机英文网站关键词优化到首页怎么做到的
  • 网站用的横幅广告怎么做seo入门培训班
  • 成品网站建设流程上海关键词优化公司哪家好
  • 建设企业网站找谁网站建设与管理是干什么的
  • 做网站 能挣钱吗江苏seo
  • 做电话销售需要的网站上海牛巨微seo
  • flash如何做网站手机网站优化排名
  • 网站容易做吗深圳推广公司哪家最好
  • 好多职业培训网站是怎么做的深圳营销推广引流公司
  • 做街舞网站的素材能搜任何网站的浏览器
  • 医疗网站建设案例兰州做网站的公司
  • 外包加工网收费seo编辑是干什么的
  • wordpress 只更鸟翻页设置seo优化的内容有哪些
  • 怎么给网站做外链网络营销常见术语
  • b2c购物商城网站建设上海百度关键词推广
  • 满城建设局官方网站网络销售培训学校
  • 家具在线设计平台百度关键词相关性优化软件
  • 网站收录差营销型网站名词解释
  • 合肥做网站yuanmus阿里巴巴推广
  • 网站后台模板关联自己做的网站珠海网络推广公司
  • 简述网站开发的几个步骤免费网站软件推荐
  • 路北网站制作网站推广的方式和方法
  • wordpress 调用指定id文章山西seo优化
  • 高档网站建设杭州推广公司
  • 插件 wordpress开发教程广州seo网站多少钱
  • 可信赖的扬中网站建设百度关键词搜索排名
  • 搭建新平台网站优化和网站推广
  • 中国最有名的建设网站建网站需要什么
  • 国外购物独立网站建设推广赚钱的软件