mauriciosoares/core.js

Feature request: Core.extend multiples like jQuery

Closed this issue · 3 comments

Is possible add this a original source?

 /**
 * Extends core functionalities
 */
 var extend = function() {
       var hasOwnProperty = Object.prototype.hasOwnProperty;     

       for (var i = 0; i < arguments.length; i++) {
              var implementation = arguments[i]
              for (var name in implementation) {
                     if (hasOwnProperty.call(implementation, name)) {
                         extensions[name] = implementation[name]
                    }
             }
        }
 };

Use as:

  // in js file anonimous function
 var test = function(){
       return 'Hello World!';
 };

 // core extends multiples like:
 Core.extend({
       '$'              : jQuery,        // obvious
       Markdown: showdown, // e.g:
       Test:          : test             // utility ?
 });

Call this:

 Core.register('boot', function(sandbox){
         return {
              init: function(){
                  this.Teste = sandbox.use('Test');
                  this.notify('teste', {});
              },
              destroy: function(){},
              notify: function(type, object){
                      sandbox.notify({
                             type:   type,
                             data:   object
                      });
                      console.log(this.Test()); // output in console "Hello World!"
              }
         };
  });

  Core.start('boot');

Proposal: extend regular functions or variables all modules in unique step

PS: like this source :)

Hey @subversivo58!

To be completely honest this project was kinda abandoned... :/ But if you open a pull request I'll be glad to accept it, it's indeed a good feat :)

É uma pena que abandonaste...quando o suporte ao autoload de es6 finalmente chegar este será uma mão na roda

dropped in favor of #54