Moviri / recline

A simple but powerful library for building data applications in pure Javascript and HTML.
http://reclinejs.com/
MIT License
2 stars 2 forks source link

Hot to extend objects having access to closure object #108

Open scriminaci opened 11 years ago

scriminaci commented 11 years ago

var ciccio = function(){ var data = { hello: function(){return "hello world!"} };

return {
    extendWith: function(extender) {
      extender.call(this, data);
      return this;
    },
    ciao: function(){
        console.log(data.hello());
    }                        ,
    ele: 10
};

}();

var pippo = function (){
var self = ciccio.extendWith(function(data) { data.hellohello = function() {
return data.hello()+' '+data.hello();
}; this.ciaociao = function() {
console.log(data.hellohello()); };
});

return self;    

}();

ciccio.ciao(); pippo.ciaociao();