js面向对象封装例子

<html>
<head>

<script type="text/javascript">

window.onload = function(){

LOGIN.ID('aaaa');

temp = "bbb";

alert(LOGIN.test.f1('zhangsan'));
alert(LOGIN.test.o2.a);

};

(function(arg){

alert(arg+100);

window.LOGIN = window.LOGIN || {};

var temp;
LOGIN.ID = function(id) {
    if (typeof id === 'string') {
        temp = id;
    } else {
        temp = '';
    }
};

LOGIN.test = {
    f1:function(name){return name+":say2 hello world! " + temp},
    o2:{a:'11',b:'22',c:'33'}
}

})(21);

</script>
</head>
<body>
</body>
</html>

原文地址:https://www.cnblogs.com/gaotianle/p/2971116.html