You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe somebody will like it to use in the update function.
Of course for() iteration will be a bit faster than forEach() but we can live this decision to a developer.
override public function update( time:Number ):void
{
nodeList.forEach( processNode );
}
private function processNode( node:MyNode ):void
{
}
Sometimes we need to pass additional params like a "time" in the update func.
Here is the extended implementation:
public function forEach( callback : Function, ...params ) : void
{
if ( head )
{
params.unshift( null );
for( var node : Node = head; node; node = node.next )
{
params[0] = node;
callback.apply( null, params );
}
}
}
Now update function can look like:
override public function update( time:Number ):void
{
nodeList.forEach( processNode, time );
// nodeList.forEach( processNode ); - will work fine too
}
private function processNode( node:MyNode, time:Number ):void
{
}
Also can be an implementation with checking a value returned by callback.apply( null, params ); and if this value == false break forEach loop :)
The text was updated successfully, but these errors were encountered:
Hi Richard,
how about to add forEach() method to the NodeList?
simple example of use in a System:
Maybe somebody will like it to use in the update function.
Of course for() iteration will be a bit faster than forEach() but we can live this decision to a developer.
Sometimes we need to pass additional params like a "time" in the update func.
Here is the extended implementation:
Now update function can look like:
Also can be an implementation with checking a value returned by callback.apply( null, params ); and if this value == false break forEach loop :)
The text was updated successfully, but these errors were encountered: