简体   繁体   中英

what do you call this design pattern Polymer and Backbone use for parameters

In Polymer and Backbone.js I was digging through the source to find out how they organize their API's for the user. Currently I'm using a revealing pattern and runs NAMESPACE.init(args) but I liked the way those two libs are making you set everything in the ready or attached methods as callback functions but I don't know the name to do some more research on it with.

Example: I call Polymer and assign something into its ready method as a callback function, I assume it's just overwriting an internal ready method and it stores it for later. Backbone looks mostly the same

Polymer({
   ready: function() {
        console.log("im ready like!")
   }
});

Perfect I guesss.. using underscore.js extend function rather then jquerys in this example but I guess jquery would work all the same.

Tacos = function (args) {
    this.commands = {
        popcorn : function(){
            console.log("pop'n fun!");
        },
        render : function(){
            vars.mine = args.cat;
        }
    }
    // using underscore.js _.extend function
    // this merges the commands and replaces the popcorn function with
    // the users function! Fun!
    _.extend(this.commands, args);

}
var u = new Tacos({
    popcorn : function(){
        console.log("popcorn denied a tron! ");
    }
});

u.commands.popcorn()// should return "popcorn denied a tron!" 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM