Last active
September 24, 2015 09:24
-
-
Save kurorido/f6e1e8aa21df1bbe8862 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var basketModule = (function() { | |
var basket = []; | |
return { | |
addItem: function(values) { | |
basket.push(values); | |
}, | |
getItemCount: function() { | |
return basket.length; | |
}, | |
getTotal: function() { | |
var q = this.getItemCount(),p = 0; | |
while(q--) { | |
p += basket[q].price; | |
} | |
return p; | |
} | |
}; | |
})(); | |
var item = {"price": 30}; | |
var item2 = {"price": 20}; | |
basketModule.addItem(item); | |
console.log(basketModule.getItemCount()); | |
basketModule.addItem(item2); | |
document.getElementById("result").innerHTML = basketModule.getTotal(); | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moudle = (function() { | |
var _private = { | |
i: 5, | |
get: function() { | |
console.log("Get Value: " + this.i); | |
}, | |
set: function(val) { | |
this.i = val; | |
} | |
} | |
return { | |
facade: function(args) { | |
_private.set(args.val); | |
_private.get(); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Tasker($, options) { | |
var internal = []; | |
var value1 = options.value1; | |
function pushItem(item) { | |
internal.push(item); | |
} | |
function getLength() { | |
return internal.length; | |
} | |
function appendText() { | |
$("div").append("Some appended text."); | |
} | |
function getOptionsValue(key) { | |
return options[key]; | |
} | |
return { | |
pushItem: pushItem, | |
getLength: getLength, | |
appendText: appendText, | |
getOptionsValue: getOptionsValue | |
}; | |
} | |
var t1 = Tasker(jQuery, { value1: "t1"}); | |
var t2 = Tasker(jQuery, { value1: "t2"}); | |
t1.pushItem(1); | |
console.log("t1 len " + t1.getLength()); | |
console.log("t2 len " + t2.getLength()); | |
t2.pushItem(1); | |
console.log("t1 len " + t1.getLength()); | |
console.log("t2 len " + t2.getLength()); | |
t1.pushItem(1); | |
console.log("t1 len " + t1.getLength()); | |
console.log("t2 len " + t2.getLength()); | |
t1.appendText(); | |
console.log("t1 key " + t1.getOptionsValue("value1")); | |
console.log("t2 key " + t2.getOptionsValue("value2")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment