From: Daniel Brooks Date: Thu, 24 Mar 2011 23:08:14 +0000 (-0500) Subject: add some comments to explain why it does what it does X-Git-Tag: v0.5~46 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=e51a93bfd2a1537a55d57af3b1924f54be723f02;p=popcorn-js.git add some comments to explain why it does what it does --- diff --git a/popcorn.js b/popcorn.js index 1735945..b12f05d 100644 --- a/popcorn.js +++ b/popcorn.js @@ -825,11 +825,17 @@ 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 ) { @@ -838,11 +844,15 @@ 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 {