close

<code> 
var emp = function(config){
                                this.name ;
                                this.nick ;
                                this.stand = function(){
                                        document.write(this.name +" " + this.nick);
                                }
                                this.init = function(){
                                        //也可以是反過來
                                        this.name = this.name? this.name : config.name;
                                        this.nick = this.nick ? this.nick :config.nick;
                                        this.stand();

                                };
                                this.init();
                                this.stand();
                    }


                        var conf = {name:"Hank",nick:"ming"};
                        var _emp = new emp(conf);
                        //_emp.init();
                        //_emp.stand();
</code>

可以在stand()內執行要執行的東西! GOOD 物件化!

 

用this 而不用 var 的好處是
          1. 可以直接把屬性抓出來用! 比較好用
          2. 可以用override的方式去改寫某些屬性

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 minglight 的頭像
    minglight

    minglight

    minglight 發表在 痞客邦 留言(0) 人氣()