如何在Object Literal Notation上使用它作为主对象

时间:2013-05-22 04:12:56

标签: javascript object-literal

我正在学习对象文字符号,但我正在尝试,或者我认为我做的事情有点复杂。例如

我想要完成的是

  • 初始化我的对象
  • 存储jquery对象
  • 申请JSON
  • 使用该JSON构建一些html 并使用承诺

(免责声明,我希望你可以原谅我的英语和我缺乏远见,明确指出我的问题)

var objeto = objeto || (objeto = {
    jsonUrl:"/something",
    container:{},
    triggerContainer:{}, 
    property1:{},
    init:function(var0,var1){
        this.container = $(var0);
        this.triggerContainer = $(var1);
        // ignoring some details I proceed to set my event
        this.loader()
    },
    loader:function(){
        // Here my scope is objeto, so far so good
        // But I have create self because my scope is about to change, am I right?
        self = this;
        this.triggerContainer.on("click",function(){
            // now, I'm going to request the json making a promise
            promiseME = jQuery.getJSON(self.jsonUrl);
            promiseME.done(self.Build);
            // NOW, I did it in this way beacuse I think it looks a bit cleaner
            // Of course my problem come next
        });
    },
    build: function(data) {
        /*
          here it is, now this is scoped for the promise, and I want to use data 
          to build some html, but I want to append to objeto.container, and I don't 
          know how to access, and I did even know how to pass a refence with .done()

        */
    }

});

我很确定,我搞砸了这种结构。也许我没有正确使用。如果是的话,请你解释一下我做错了什么

提前谢谢大家。

0 个答案:

没有答案