• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. Javascript自定義類型的幾種方法小結(jié)

        時間:2024-09-16 16:41:56 JavaScript 我要投稿
        • 相關(guān)推薦

        Javascript自定義類型的幾種方法小結(jié)

          1. 定義類型

          復(fù)制代碼 代碼如下:

          function UserObject(parameter) {

          }

          parameter 可省略,相當于C#中構(gòu)造函數(shù)參數(shù)。

          2. 實例化自定義類型

          復(fù)制代碼 代碼如下:

          function userobject(parameter){

          }

          //myobject is now an object of type userobject!

          var myobject=new userobject("hi")

          alert(myobject)

          3. 添加屬性

          復(fù)制代碼 代碼如下:

          function userobject(parameter){

          this.firstproperty=parameter

          this.secondproperty="This is the second property"

          }

          //使用

          復(fù)制代碼 代碼如下:

          var myobject=new userobject("hi there.")

          //alerts "hi there."

          alert(myobject.firstproperty)

          //writes "This is the second property"

          document.write(myobject.secondproperty)

          4.添加方法 (circle類)

          復(fù)制代碼 代碼如下:

          //first method function

          function computearea(){

          var area=this.radius*this.radius*3.14

          return area

          }

          //second method function

          function computediameter(){

          var diameter=this.radius*2

          return diameter

          }

          關(guān)聯(lián)到自定義類型:

          復(fù)制代碼 代碼如下:

          /*the below creates a new object, and gives it the two methods defined earlier*/

          function circle(r){

          //property that stores the radius

          this.radius=r

          this.area=computearea

          this.diameter=computediameter

          }

          使用自定義方法:

          復(fù)制代碼 代碼如下:

          var mycircle=new circle(20)

          //alerts 1256

          alert("area="+mycircle.area())

          //alerts 400

          alert("diameter="+mycircle.diameter())

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

        【Javascript自定義類型的幾種方法小結(jié)】相關(guān)文章:

        速寫有哪些幾種表現(xiàn)方法和類型05-18

        JavaScript常用方法匯總10-25

        關(guān)于數(shù)據(jù)類型的Javascript學(xué)習(xí)筆記08-05

        街舞有幾種類型05-05

        公文類型有幾種06-29

        JavaScript數(shù)組常用方法介紹09-04

        javascript跨域訪問的方法07-09

        javascript編程異常處理的方法08-04

        JavaScript fontcolor方法入門實例07-07

        留學(xué)法國的幾種獎學(xué)金類型06-13

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 夜夜久久国产精品亚州AV | 亚洲五月综合缴情在线观看 | 午夜精品福利网站 | 亚洲免费片在线观看 | 日韩免费看视频三区中文字幕 | 色资源站欧美在线 |
            • 相關(guān)推薦

            Javascript自定義類型的幾種方法小結(jié)

              1. 定義類型

              復(fù)制代碼 代碼如下:

              function UserObject(parameter) {

              }

              parameter 可省略,相當于C#中構(gòu)造函數(shù)參數(shù)。

              2. 實例化自定義類型

              復(fù)制代碼 代碼如下:

              function userobject(parameter){

              }

              //myobject is now an object of type userobject!

              var myobject=new userobject("hi")

              alert(myobject)

              3. 添加屬性

              復(fù)制代碼 代碼如下:

              function userobject(parameter){

              this.firstproperty=parameter

              this.secondproperty="This is the second property"

              }

              //使用

              復(fù)制代碼 代碼如下:

              var myobject=new userobject("hi there.")

              //alerts "hi there."

              alert(myobject.firstproperty)

              //writes "This is the second property"

              document.write(myobject.secondproperty)

              4.添加方法 (circle類)

              復(fù)制代碼 代碼如下:

              //first method function

              function computearea(){

              var area=this.radius*this.radius*3.14

              return area

              }

              //second method function

              function computediameter(){

              var diameter=this.radius*2

              return diameter

              }

              關(guān)聯(lián)到自定義類型:

              復(fù)制代碼 代碼如下:

              /*the below creates a new object, and gives it the two methods defined earlier*/

              function circle(r){

              //property that stores the radius

              this.radius=r

              this.area=computearea

              this.diameter=computediameter

              }

              使用自定義方法:

              復(fù)制代碼 代碼如下:

              var mycircle=new circle(20)

              //alerts 1256

              alert("area="+mycircle.area())

              //alerts 400

              alert("diameter="+mycircle.diameter())