Lively Kernel canvas
LayerDefinitionandApplication40true
Wikicontroltruetrue
function(){return3}
basefunction
nullnull-0.04676895796431805
m:function(proceed){returnproceed()+4}
nullnull0.016657266840925618
o1
function(){varargs=$A(arguments);args.unshift(null);//emptyproceedargument(performanceoptimisationuglyness)returnexecuteWithLayers(base_function,this,computerLayersFor(this),0,base_obj,function_name,args);}4
nullnull1.4828685873210672
true
afterthemethodwasmadelayeraware
computerLayersFor=functionLayers$computerLayersFor(obj){if(obj&&obj.activeLayers){//theobjectisnowfullyresponsibleforthelayercompositionreturnobj.activeLayers(Global.currentLayers);};varlayers=Global.currentLayers(obj);returnlayers;};7
nullnull-0.8484168363830187
true
generatedfunction
activeLayers
nullnull1.3849148106242741
true
ContextJSasitis,withsupportforobjectspecificlayercompositionbutwithafallybacktothedefaultbehavior117
1.behaviorialvariationsaregroupedinalayerassetofpartialmethodsdefinitions2.themethodintheobjectshavetobemadelayerawarebyusingmethodwrappers(closures)3.thesewrappermethodscomputealayercomposition,whichisusedinthefurhterdispatch/executionofthemethod217
nulltrue
o1:Object
m
nulltrue
L:layer
log=function(s){WorldMorph.current().setStatusMessage(""+s)}o1=newObject();o1.m=function(){return3}cop.create("L").refineObject(o1,{m:function(proceed){returnproceed()+4}})o1.m()//3withLayers([L],function(){log(o1.m())//7})o2=newObject();o2.foo=function(){return"Hello"}L.refineObject(o2,{foo:function(proceed){returnproceed()+"World"}})withLayers([L],function(){log(o2.foo())//"HelloWorld:})1426
executeWithLayers=function(base_function,self,layers,index,obj,function_name,args,methodType){if(index<layers.length){varlayer=layers[layers.length-index-1];varlayered_function=lookupLayeredFunctionForObject(self,layer,obj,function_name,methodType);if(layered_function){varnew_proceed=function(){varnew_arguments=$A(arguments);new_arguments.unshift(null);returnexecuteWithLayers(base_function,self,layers,index+1,obj,function_name,new_arguments,methodType);};args[0]=new_proceed;returnlayered_function.apply(self,args);}returnexecuteWithLayers(base_function,self,layers,index+1,obj,function_name,args,methodType);};args.shift();//removeproceedargumentreturnbase_function.apply(self,args);};17
recursivefunctionthatexecutesmethodwithaspecificlayercomposition
OptimizationQuestions:Canweavoidcreatingunessarayobjects?Canwemakethefunctioniterativeandnotrecursive?2
null71