> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter1/12javascript-quan-gong-lve-ff1a-ke-fu-js-de-qi-guai-bu-fen/128lai-da-zao-yi-ge-kuang-67b6-zi-yuan-ku/1283wo-men-de-wu-jian-yu-qi-yuan-xing.md).

# 1.2.8.3.我們的物件與其原型

* 用[IIFE](https://jenhsuan.gitbooks.io/javascript-node-js/content/chapter1/12316kuang-jia-xiao-ding-ning-ff1a-iifes-yu-an-quan-cheng-shi-ma.html)時, 裡面的變數與全域是各自獨立的

```
(function (global, $) {
    //不需要每次都使用new
    var Greetr = function (firstname, lastname, language) {
        return new Greetr.init(firstname, lastname, language)
    }

    Greetr.prototype = {};

    //用new建構子呼叫時, this會指向新建立的空物件
    Greetr.init = function (firstname, lastname, language) {
        var self = this;
        self.firstname = firstname || '';
        self.lartname = lastname || '';
        self.language = language || 'en';
    }

    //由Greetr.init所建立的物件應該指向Greetr.prototype作為原型鍊
    Greetr.init.prototype = Greetr.prototype;

    //IIFE外面的Greetr(別名G$)會指向Greetr
    global.Greetr = global.G$ = Greetr;

}(window, jQuery));
```
