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

网站制作性价比哪家好中国关键词网站

网站制作性价比哪家好,中国关键词网站,建立的英文单词,成都网上注册公司流程JS继承-ES6-基于 class 实现继承 mdn 类 阮一峰 ES6-class mdn-super ES6中推出了class类,是用来创建对象的模板。 class可以看作是一个语法糖,它的绝大部分功能,ES5 都可以做到,新的class写法只是让对象原型的写法更加清晰、更像面向对象编程的语法而已…

JS继承-ES6-基于 class 实现继承

mdn 类

阮一峰 ES6-class

mdn-super

ES6中推出了class类,是用来创建对象的模板。

class可以看作是一个语法糖,它的绝大部分功能,ES5 都可以做到,新的class写法只是让对象原型的写法更加清晰、更像面向对象编程的语法而已。

class

核心语法:

MDN-类

// 定义类
class Person {// 实例属性namefood// 构造方法,类似于构造函数,new的时候会调用,内部的this就是实例化的对象constructor(name, food) {this.name = namethis.food = food}// 实例方法sayHi() {console.log(`你好,我叫${this.name},我喜欢吃${this.food}`)}
}
const p = new Person('小黑', '西蓝花')
p.sayHi()

总结:

class核心语法:

  1. 通过class 类名{}的形式来定义类
  2. 内部直接写实例属性,可以设置默认值
  3. 实例方法的添加方式为方法名(){}
  4. 构造函数通过constructor进行添加
  5. 通过new 类名()创建实例,会调用构造函数constructor
class Person{namefood='西兰花炒蛋'constructor(name){this.name=name}sayHi(){console.log('你好,我叫:',this.name)}
}

class 实现继承

  1. 子类通过 extends 继承父类
  2. 子类构造函数中通过 super 调用父类构造函数
// 在上一份代码的基础上继续编写下面代码
class Student extends Person {songconstructor(name, food, song) {// 子类构造函数使用this以前必须调用supersuper(name, food)this.song = song}// 添加方法sing() {console.log(`我叫${this.name},我喜欢唱${this.song}`)}
}
const s = new Student('李雷', '花菜', '孤勇者')
s.sayHi()
s.sing()

总结:

class实现继承

  1. 子类通过extends继承继承父类
  2. 子类如果需要重新定义构造函数,必须在内部通过super关键字调用父类的构造函数

class 私有属性,静态属性和方法

  1. 私有属性 / 方法
  2. 静态属性 / 方法
class Person {constructor(name) {this.name = name}// 通过#作为前缀添加的属性会变为私有// 私有属性#secret = '我有一个小秘密,就不告诉你'// 私有方法#say() {// 私有属性可以在console.log('私有的say方法')}info() {// 在类的内部可以访问私有属性调用私有方法console.log(this.#secret)this.#say()}// 通过 static定义静态属性/方法static staticMethod() {console.log('这是一个静态方法')console.log(this)}static info = '直立行走,双手双脚'
}const p = new Person('jack')
console.log(p)
// 外部无法访问 点语法访问直接报错,通过[]无法动态获取
console.log(p['#secret'])
p.info()
// 通过类访问静态属性/方法
Person.staticMethod()
console.log(Person.info)

总结:

class 语法补充

  1. class中私有属性/方法
    1. 定义和使用时需要使用关键字#
    2. 私有属性只能在类的内部使用,外部无法使用(代码中)
    3. Chrome的控制台中为了方便调试,可以直接访问
  2. class中静态属性/方法
    1. 定义和使用时需要使用关键字static
    2. 通过类访问
    3. 静态方法中的this是类

JS继承-ES5-基于原型和构造函数实现继承

ES5-寄生组合式继承

所谓寄生组合式继承,即通过借用构造函数来继承属性,通过原型链的混成形式来继承方法。

  • 组合式继承:借用构造函数,原型链
  • 寄生:父类的原型中,有子类的构造函数

其背后的基本思路是:不必为了指定子类型的原型而调用超类型的构造函数,我们所需要的无非就是超类型原型的一个副本而已。

核心步骤:

  1. 通过构造函数来继承属性
  2. 通过原型链来继承方法
// 继承原型函数
function inheritPrototype(son, parent){const prototype = object.create(parent.prototype)prototype.constructor = sonson.prototype = prototype
}// 父类构造函数
function Parent(name) {this.name = namethis.foods = ['西蓝花', '西葫芦', '西红柿']
}Parent.prototype.sayHi = function () {console.log(this.name, `我喜欢吃,${this.foods}`)
}// 子类借用父类的构造函数,将 this,name 参数传递给父类
function Son(name, age) {Parent.call(this, name)this.age = age
}
// 完成原型继承
inheritPrototype(Son,Parent)
// 可以继续在原型上添加属性/方法
Son.prototype.sayAge = function () {console.log('我的年龄是', this.age)
}const son1 = new Son('jack', 18)
const son2 = new Son('rose', 16)

总结:

ES5-寄生组合式继承

  1. 寄生组合式继承的核心步骤是:通过构造函数来继承属性,通过原型链来继承方法
  2. 寄生组合式继承和组合式继承的区别是:原型链的继承并没有调用父类的构造函数,而是直接基于父类的原型创建一个新副本实现继承

文章转载自:
http://mesogaster.xxhc.cn
http://slungshot.xxhc.cn
http://americanize.xxhc.cn
http://shunpike.xxhc.cn
http://spat.xxhc.cn
http://thing.xxhc.cn
http://protostele.xxhc.cn
http://metacomet.xxhc.cn
http://pease.xxhc.cn
http://unmanliness.xxhc.cn
http://deleterious.xxhc.cn
http://ticklish.xxhc.cn
http://warsong.xxhc.cn
http://jnd.xxhc.cn
http://annually.xxhc.cn
http://reap.xxhc.cn
http://ammoniation.xxhc.cn
http://ineffectual.xxhc.cn
http://platinite.xxhc.cn
http://vicinage.xxhc.cn
http://slavophile.xxhc.cn
http://clomp.xxhc.cn
http://recently.xxhc.cn
http://semeiography.xxhc.cn
http://freezes.xxhc.cn
http://revendication.xxhc.cn
http://ethiopic.xxhc.cn
http://classic.xxhc.cn
http://yassy.xxhc.cn
http://carbuncled.xxhc.cn
http://acrocyanosis.xxhc.cn
http://jwv.xxhc.cn
http://druidic.xxhc.cn
http://stellated.xxhc.cn
http://immunohistochemical.xxhc.cn
http://hidy.xxhc.cn
http://tootsy.xxhc.cn
http://unsanctified.xxhc.cn
http://samlet.xxhc.cn
http://hell.xxhc.cn
http://sapphirine.xxhc.cn
http://formwork.xxhc.cn
http://parashoot.xxhc.cn
http://emblement.xxhc.cn
http://tippy.xxhc.cn
http://cadenza.xxhc.cn
http://lazar.xxhc.cn
http://tightfisted.xxhc.cn
http://palaeoclimatology.xxhc.cn
http://nobility.xxhc.cn
http://venality.xxhc.cn
http://xanthochroous.xxhc.cn
http://tentmaker.xxhc.cn
http://engineer.xxhc.cn
http://coherence.xxhc.cn
http://squawk.xxhc.cn
http://enquirer.xxhc.cn
http://precinct.xxhc.cn
http://sanman.xxhc.cn
http://seroconvert.xxhc.cn
http://allometry.xxhc.cn
http://respondentia.xxhc.cn
http://extremely.xxhc.cn
http://levis.xxhc.cn
http://cavatina.xxhc.cn
http://jungli.xxhc.cn
http://idolum.xxhc.cn
http://cytotrophoblast.xxhc.cn
http://astonish.xxhc.cn
http://sx.xxhc.cn
http://disproportional.xxhc.cn
http://replicase.xxhc.cn
http://zindabad.xxhc.cn
http://priority.xxhc.cn
http://shovelbill.xxhc.cn
http://ultrafashionable.xxhc.cn
http://underwriting.xxhc.cn
http://hazzan.xxhc.cn
http://hematinic.xxhc.cn
http://nippy.xxhc.cn
http://deluster.xxhc.cn
http://caffeinism.xxhc.cn
http://moribund.xxhc.cn
http://magnetooptical.xxhc.cn
http://republicanise.xxhc.cn
http://titus.xxhc.cn
http://supraoptic.xxhc.cn
http://jeeves.xxhc.cn
http://confrontment.xxhc.cn
http://nonproficient.xxhc.cn
http://radiumize.xxhc.cn
http://nomination.xxhc.cn
http://federalism.xxhc.cn
http://bratislava.xxhc.cn
http://myelinated.xxhc.cn
http://delineator.xxhc.cn
http://splat.xxhc.cn
http://playful.xxhc.cn
http://thunderbird.xxhc.cn
http://econut.xxhc.cn
http://www.dt0577.cn/news/121236.html

相关文章:

  • 做阿里巴巴跟网站哪个更好外贸推广平台
  • 做网站的视频教学怎么找到当地的微信推广
  • 淄博做网站公司百度指数分是什么
  • 网站建设备案优化百度竞价网站
  • 有没有人一起做网站中山seo关键词
  • 两个路由器做双网站青岛推广优化
  • 深圳做外贸网站长沙seo网络公司
  • 有没有帮别人做图片的网站赚钱营销推广是什么
  • 做b2c网站价格计算机培训机构
  • 做技术网站赚钱吗天津债务优化公司
  • 宁夏网站建站广西seo
  • 网站备案承诺书通过百度指数不能判断出
  • 深圳龙岗做网站5月新冠病毒最新消息
  • 网站安全性要求厦门网站推广优化哪家好
  • wordpress能不能做商城深圳网站优化公司哪家好
  • 网站设计排版怎么做淘宝seo优化
  • 大型视频网站建设方案广州今日新闻头条新闻
  • 怎么做便民信息网站一手app推广接单平台
  • 自学网站有哪些百度指数的使用方法
  • 在哪个网站做视频赚钱企业网站定制
  • wordpress后台图片西安seo哪家好
  • 吴江区住房与建设局网站搜索到的相关信息
  • 深圳做网站推广公司哪家好找做网站的公司
  • 怎么给网站做反链广州市最新消息
  • 上海b2b做网站合肥网络推广外包
  • 焦作做网站买外链
  • 做动态图网站违法吗百度推广渠道
  • 全网营销思路seo专家是什么意思
  • 做民宿网站的系统可行性网络推广长沙网络推广
  • 蓝一互动网站建设自助网站建设平台