jquery - pass parents function arguments in a nested function? -


i having problem arguments object in nested function, seems arguments.length taken parent function while arguments[0] taken nested function... can explain why happening ?and show me effective way pass parent foo's arguments bar?

$.fn.foo = function(color1, color2, time ){     return this.each(function bar(){          for(var = 0;i < (arguments.length - 1);i++){             alert(arguments.length); //this taken foo function , returns 2            alert(arguments[i]); //this taken  bar           }     });     }; 

simple solution: local reference arguments.

$.fn.foo = function(color1, color2, time ){     var args = arguments; // create private reference     return this.each(function bar(){         alert(args.length); //use private reference     }); }; 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -