js单例模式
fkshl
2012-07-09
申名是书上抄来的,大家一起学习.
GiantGorp = {}; GiantGorp.DataParser = (function() { var reg = /\s+/gi; function tirm(str) { return str.replace(reg, ""); } function split(str, delimiter) { return str.split(delimiter); } return { toArray : function(str, delimiter, isTirm) { if (!str) return; if (isTirm) str = tirm(str); return split(str, delimiter); } } })(); GiantGorp.singleton = (function() { var uniqueInstance; function constructor() { var reg = /\s+/gi; function tirm(str) { return str.replace(reg, ""); } function split(str, delimiter) { return str.split(delimiter); } return { toArray : function(str, delimiter, isTirm) { if (!str) return; if (isTirm) str = tirm(str); return split(str, delimiter); } } } return { getInstance : function() { if (!uniqueInstance) { uniqueInstance = constructor(); } return uniqueInstance; } } })(); |
|
it_boy1986
2013-12-31
|
|
it_boy1986
2013-12-31
|