窮小子

          MajorYe
          數據加載中……
          javascript中Function與function的特殊之處

          Function()的特殊之處有三點:
          1: Function() constructor 它是允許js引擎動態的去編譯和運行,所以它很像全局的eval()。
             【注】:可別小看這個eval(),它可是js的一個解釋器哦,嘿嘿!
          2:正因為 Function() constructor 是動態的去創建函數體,因此它會比直接function定義函數要消耗資源,
                特別在循環中不推薦使用
          3:這點也是 Function() constructor 最重要的一點, Function() constructor 創建的函數是全局的,而不是相
             應得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) 評論(0)  編輯  收藏 所屬分類: WEB開發

          主站蜘蛛池模板: 阜南县| 开阳县| 左贡县| 延边| 东明县| 洪江市| 科技| 潼南县| 牟定县| 芮城县| 无锡市| 富宁县| 师宗县| 石柱| 榆社县| 鄂伦春自治旗| 阿合奇县| 溧水县| 资溪县| 阿拉善右旗| 来安县| 株洲市| 苍南县| 元氏县| 手机| 贵港市| 抚松县| 西宁市| 田东县| 内丘县| 西峡县| 阿拉善右旗| 新平| 阿拉善盟| 江口县| 西藏| 宿迁市| 莱芜市| 县级市| 牟定县| 北京市|