首页 > 其他 > 详细

ES6

时间:2020-07-12 12:00:34      阅读:57      评论:0      收藏:0      [点我收藏+]

构造函数class   普通函数function

class Person {

//静态属性,放置在construction中

construction(name , age){

  this.name = name

  this.age = age

}

//原型方法

eat(){

  return `$(this.name)在吃饭`

}

sleep(){

  return `$(this.name)在睡觉`

 } 

}

let p1 = new Person ("Tom", 25)

//本质上js的继承逻辑是原型链

 

-------------------------------------

function Person (name,age) {

this.name = name;

this.age = age;

}

Person.prototype.eat = function () {

return this.name+"在吃"

}

Person.prototype.sleep = function () {

return this.name+"在睡"

}

let p1 = new Person("Kim", 20)

let p2 = new Person("Ben", 30)

console.log (p1.eat === p2.eat)//true

 

ES6

原文:https://www.cnblogs.com/Topazqin/p/13287250.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!