]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
add some comments to explain why it does what it does
authorDaniel Brooks <db48x@db48x.net>
Thu, 24 Mar 2011 23:08:14 +0000 (18:08 -0500)
committerDaniel Brooks <db48x@db48x.net>
Thu, 24 Mar 2011 23:08:14 +0000 (18:08 -0500)
popcorn.js

index 17359453c23aeffb3b1903a5413a49b599b00a57..b12f05dee4ffd74e5a383f4568dbdd3feae487d0 100644 (file)
       Popcorn.error("Plugin "+ name +" can't inherit from "+ p +", which doesn't exist");
     }
 
+    // get the defining functions for all of the parent classes
+    // these are only the direct parents, it's not the full list of ancestors
+    // a refinement of this implementation will use the full ancestor
+    // list as an optimization and so that we can state precisely the
+    // order that the ancestor plugins are called in
     if ( !Array.isArray( parent ) ) {
       parent = [ parent ];
     }
     var parents = parent.map( getDefinition );
 
+    // now create the requested plugin under the reqested name
     return Popcorn.plugin( name, function( options ) {
       var self = this;
       function instantiate( p, options ) {
       function delegate( name ) {
         return function() {
           plugins.forEach( function( p ) {
+            // the new plugin simply calls the delegated methods on
+            // all of its parents in the order they were specified
             p[name] && p[name].apply( self, arguments );
           });
         };
       }
 
+      // when the newly-defined plugin is instantiated, it must
+      // explicitly instantiate all of the parents
       var plugins = parents.map(function( p ) { return instantiate( p, self, options ); });
       plugins.push( instantiate( definition, self, options ) );
       return {