<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
// function Parent(username){
// this.username=username
// this.hello=function(){
// console.log(this.username)
// }
// console.log(this)
// }
// Parent()
// function Child(u,p){
// console.log(this)
// // this.m=Parent
// // this.m(u)
// // delete this.m
// // let fn=Parent.bind(this)
// // fn(u)
// }
// let c=new Child("qqq","222")
// Child建立新的對象而後this指向是指向自己,而後使其父類成爲其一個屬性,這是父類的指向也改變了
// Parent中其調用是windows調用的因此指向windows
// 構造函數中的繼承就是經過改變父類中this指向來實現繼承.
//經過bind來綁定this指向,綁定是哪一個就是哪一個
// function box(a,b){
// console.log(this,a,b)
// }
// var arr=[111]
// box.call(arr,1,3)
//
//
// function box(a,b){
// console.log(this,a,b)
// }
// var arr=[111]
// box.apply(arr,[1,2])
// 使用call和apply的方法時就已經在調用函數,而後一一對應將值賦給this,call和apply的不一樣之處在於參數不一樣,
// let arr=[2,4,5,6,2,90,34,22,4,223,322]
// console.log(Math.min(...arr))
// var a=Math.max.apply(null,arr)
// console.log(a)
__proto__原型指針
實例裏面的__proto__原型指針都指向構造函數的原型對象
同一個構造函數的實例的原型指針都指向這個構造函數的原型對象
改變構造函數原型對象的屬性,實例都會受影響
原型鏈
自身-原型-原型.....-object-原型(null)
找屬性能夠順着原型鏈找,一層一層向上找,若是最後還找不到就是undefined
hasOwnProperty 檢查對象自己是否具備某個屬性,原型鏈上的檢測不出來
繼承
屬性寫在構造函數裏
方法寫在原型對象中
</script>
</body>
</html>javascript