JS 代碼模塊化

var module = (function() {
    var N = 5;
    function print(x) {
        console.log("The result is: " + x);
    }
    function add(a) {
        var x = a + N;
        print(x);
    }
    return {
        description: "This is description",
        add: add
    };
})();
console.log(module.description); // 輸出"this is description" 
module.add(5); // 輸出“The result is: 10”
var module = (function() {
    var N = 5;
    function print(x) {
        console.log("The result is: " + x);
    }
    function add(a) {
        var x = a + N;
        print(x);
    }
    return {
        description: "This is description",
        add: add
    };
})();
console.log(module.description); // 輸出"this is description" 
module.add(5); // 輸出“The result is: 10”

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章