窮小子

          MajorYe
          數(shù)據(jù)加載中……
          javascript中Function與function的特殊之處

          Function()的特殊之處有三點(diǎn):
          1: Function() constructor 它是允許js引擎動(dòng)態(tài)的去編譯和運(yùn)行,所以它很像全局的eval()。
             【注】:可別小看這個(gè)eval(),它可是js的一個(gè)解釋器哦,嘿嘿!
          2:正因?yàn)?nbsp;Function() constructor 是動(dòng)態(tài)的去創(chuàng)建函數(shù)體,因此它會(huì)比直接function定義函數(shù)要消耗資源,
                特別在循環(huán)中不推薦使用
          3:這點(diǎn)也是 Function() constructor 最重要的一點(diǎn), Function() constructor 創(chuàng)建的函數(shù)是全局的,而不是相
             應(yīng)得scope里面的
             eg:
            var y = "global";
            function constructFunction() {
               var y = "local";
              return new Function("return y");  // Does not capture the local scope!
          }
          // This line displays "global" because the function returned by the
          // Function() constructor does not use the local scope. Had a function
          // literal been used instead, this line would have displayed "local".
          alert(constructFunction()());  // Displays "global"

          posted on 2008-04-17 18:03 MajorYe 閱讀(426) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): WEB開(kāi)發(fā)

          主站蜘蛛池模板: 玉树县| 苍梧县| 崇信县| 永德县| 那曲县| 安溪县| 赤峰市| 略阳县| 十堰市| 甘谷县| 托克逊县| 波密县| 辽阳市| 黄冈市| 灵宝市| 长宁县| 台湾省| 汉中市| 玉溪市| 翁源县| 分宜县| 揭西县| 新龙县| 上蔡县| 凌源市| 略阳县| 泗水县| 德惠市| 会理县| 梅河口市| 永胜县| 益阳市| 金平| 绍兴县| 忻城县| 邢台县| 柳河县| 政和县| 临朐县| 西华县| 新郑市|