国产宅男网站在线|亚洲A级性爱免费视频|亚洲中精品级在线|午夜福利AA毛

  • <dd id="gf5jf"><th id="gf5jf"></th></dd>

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

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

    時(shí)間: 歐東艷656 分享

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

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


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

      javascript實(shí)例

      在本例中,我們將展示如何使用 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