原型与原型链

原型与原型链是js
js是基于原型继承的语言

1.原型概念:jsvascript都包含了一个proto内部属性,这个属性对应的是自身
除了原型proto之外,还有prototype属性,当函数对象作为构造函数创建实例时,
prototype属性值将被作为实例对象的原型proto
2.原型链当一个对象调用自身不存在的对象或者方法就会去自己proto关联的前辈prototype对象上去找,
如果没有找到,就会去prototype原型proto关联的前辈prototype,
依次类推直到undefined,这就是原型链
3.总结:JavaScript中的对象都有一个内置属性prototype,找不到就会在当前对象的原型对象中接着找,直到找到为最顶层没有的话就结束查找返回undefined
隐式原型:用来构成原型链,实现基于原型的继承
显示原型:用来实现原型的继承与属性共享

  1. 如何准确判断一个变量是不是数组?
  2. 手写一个简易的jQuery,考虑插件和扩展性
  3. class的原型本质,怎么理解?
知识点
  • class和继承
  • 类型判断instanceof
  • 原型和原型链

1.class

构建:construction 有属性、方法
//类
class Student{ //属性
	constructor(name,number){
		this.name=name
		this.number=number
	}
	sayHi(){ //方法
		console.log(
		`姓名${this.name},学号${this.number}`
		)
	}
}
//通过类 new 对象/实例
const huahua = new Student('婳婳',100)
console.log(huahua.name)
console.log(huahua.number)
huahua.sayHi()
继承
  1. extends
  2. super
  3. 扩展或重写方法
//父类
class People{
	constructor(name){
	this.name=name
	}
	eat(){
		console.log(`${this.name}eat something`)
	}
}
//父类
class Student extends People{
	construction(name,number){
		super(name)
		this.number=number
	}
	sayHi(){
		console.log(`姓名${this.name}学号${this.number}`)
	}
}
const huahua = new Student('婳婳',100)
console.log(huahua.name)
console.log(huahua.number)
huahua.sayHi()
huahua.eat()

待更新……

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值