久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      javascript的靜態(tài)方法如何使用

      javascript使用靜態(tài)方法的方法:定義一個(gè)function實(shí)際上是定義了一個(gè)類【class】,代碼為【Person.say=function(){console.log('I am a Person,I can say.')}】。

      javascript的靜態(tài)方法如何使用

      本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版,DELL G3電腦。

      javascript使用靜態(tài)方法的方法:

      靜態(tài)方法

      Person.say=function(){     console.log('I am a Person,I can say.') }; Person.say(); //正常運(yùn)行 var carl=new Person; carl.say(); //報(bào)錯(cuò)

      我們給Person這個(gè)類添加了一個(gè)say方法,它在類上面的,所以,它實(shí)際上是一個(gè)靜態(tài)方法.

      靜態(tài)方法:不能在類的實(shí)例上調(diào)用靜態(tài)方法,而應(yīng)該通過(guò)類本身調(diào)用。

      類(class)通過(guò) static 關(guān)鍵字定義靜態(tài)方法。以上對(duì)Person.say方法的定義等同于:

      class Person {   static say() {     return console.log('I am a Person, I can say.');   } }

      實(shí)例方法

      Person.prototype.getName=function(name){     console.log('My name is '+name); } Person.getName('Carl'); //報(bào)錯(cuò) var carl=new Person; carl.getName('Carl'); //正常運(yùn)行

      getName這個(gè)方法實(shí)際上是在prototype上面的,只有創(chuàng)建一個(gè)實(shí)例的情況下,才可以通過(guò)實(shí)例進(jìn)行訪問(wèn)。

      相關(guān)免費(fèi)學(xué)習(xí)推薦:javascript視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)