recursion - Javascript 'this' overwriting in Z combinator and every other recursive function -


background:

i have recursive function implemented z-combinator shown here , here makes no use of arguments.callee since deprecated in upcoming es6.

issue

the main issue z-combinator , recursive anonymous functions i've seen far updates de this value inner function scope (the self-returned @ return clause), this references top level lost, , want maintain through inner functions.

is there way maintain top level this without passing additional function argument, obvious way rid of issue not clean want?

edit:

right solve issue passing top this reference z-combinator this:

co.utilities.z(this.createhtmlfromlom)(this.lom, this); 

in recursive function return same function passing top value this:

function createhtmlfromlom(callee:any, lom_section:lom, self:any):void {     /* other code. */     return callee(lom_section.children[widget], self); } 

this z-combinator definition:

function z(func:any):any {         var f = function () {             return func.apply(null, [f].concat([].slice.apply(arguments)));         };          return f;     } 

thanks

you following :

var me = this;

and pass me argument z combinator.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -