js封装自己的类库
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>js封装自己的类库</title>
</head>
<body>
<script type="text/javascript">
// 定义类
(function(win){
var ZhuZhuSoft = win.ZhuZhuSoft = win.ZhuZhuSoft ||
{
global: win
};
ZhuZhuSoft.version = function() {
alert("1.0");
};
ZhuZhuSoft.NSLog = function(s) {
alert(s);
};
if(win.Z == undefined)
win.Z = ZhuZhuSoft;
})(window);
(function() {
var Text = ZhuZhuSoft.Text = function() {
};
Text.prototype.version = function() {
alert("Text version1.0");
};
})();
(function() {
var IO = ZhuZhuSoft.IO = function() {
};
IO.prototype.version = function() {
alert("IO version1.0");
};
})();
// 使用类方法以及对象方法
Z.version();
Z.NSLog("猪猪SOFT");
var text = new Z.Text();
text.version();
var io = new Z.IO();
io.version();
</script>
</body>
</html>