欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

JavaScrpt的原型使用方法以及原型域和原型鏈的介紹

使用原型

成都創(chuàng)新互聯(lián)專注于那坡企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,商城網(wǎng)站建設(shè)。那坡網(wǎng)站建設(shè)公司,為那坡等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站建設(shè),專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

一、原型屬于一類普通對象 即是Object() 自動創(chuàng)建,

1、通過原型添加屬性
function a(x){
this.x = x;

}

a.prototype.x = 2 //添加屬性
var a1=new a(4)
a.prototype.x= a1.x  //將本地屬性傳遞給原型屬性
2、使用原型添加方法 和 使用原型來繼承

function a(x,y,z){
this.x=x;
this.y=y;
this.z=z;

}

a.proptype.add=function(a,b){ //添加方法

return a+b;
}
使用原型實現(xiàn)繼承
function Parent(x){
this.x=x
console.log(x)
}

function Child(y){
this.y=y;
console.log(y)
}

//實例化一個父實例

var parent = new Parent("父");

Child.proptype=parent;

//實現(xiàn)一個子實例

var child=new Child("子")

child.x
child.y

原型域和原型域鏈
在javaScript 在實例讀取對象屬性時候,總是先檢查自己本地屬性,假如存在,則返回本地屬性,如果不存在則往通過prototype原型域查找,返回原型域中的屬性

Function.prototype.a=function(){
alert("Function")
}
object.prototype.a =function(){
alert("Oject")

}
function f(){
this.a = a
}

f.prootype ={
n:function(){

alert("w")
}
}

console.log( f instancef Function );//true
console.log( f.prototype instancef Object) //true
console.log(Fnction instaceof Object Ojbect) //true

文章名稱:JavaScrpt的原型使用方法以及原型域和原型鏈的介紹
文章地址:http://chinadenli.net/article8/pippip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)頁設(shè)計公司、軟件開發(fā)外貿(mào)網(wǎng)站建設(shè)、全網(wǎng)營銷推廣手機網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站