亚洲欧美精品沙发,日韩在线精品视频,亚洲Av每日更新在线观看,亚洲国产另类一区在线5

<pre id="hdphd"></pre>

  • <div id="hdphd"><small id="hdphd"></small></div>
      學(xué)習(xí)啦 > 知識大全 > 知識百科 > 百科知識 > js中構(gòu)造函數(shù)是什么

      js中構(gòu)造函數(shù)是什么

      時間: 歐東艷656 分享

      js中構(gòu)造函數(shù)是什么

        構(gòu)造函數(shù)(constructor)是一種特殊的方法 。主要用來在創(chuàng)建對象時初始化對象, 即為對象成員變量賦初始值,總與new運算符一起使用在創(chuàng)建對象的語句中 。特別的一個類可以有多個構(gòu)造函數(shù) ,可根據(jù)其參數(shù)個數(shù)的不同或參數(shù)類型的不同來區(qū)分它們 即構(gòu)造函數(shù)的重載。構(gòu)造函數(shù)的功能主要用于在類的對象創(chuàng)建時定義初始化的狀態(tài)。


      構(gòu)造函數(shù)

        javascript實例

        在本例中,我們將展示如何使用 constructor 屬性。

        vartest=newBoolean();

        if(test.constructor==Array)

        {

        document.write("ThisisanArray");

        }

        if(test.constructor==Boolean)

        {

        document.write("ThisisaBoolean");

        }

        if(test.constructor==Date)

        {

        document.write("ThisisaDate");

        }

        if(test.constructor==String)

        {

        document.write("ThisisaString");

        }

      246707