hi all,
say i have the following code:
var something = {
array1: [....],
var1: 0,
// should the iterator func be place here
display: function() {
// or here?
this.array1.each(iteratorfunc); // doesnt have to be each,
could be any enumerable function
}
}
assume: the function display gets call a lot, and the iterator
function needs to access var1
1) if i defined the iterator function inside display, the iterator
function/closure will get created everytime i call display....
2) if i defined the iterator outside display function, i ll need to
use bind(this) so the function has access to the var1 variable
the question is, is option 1, creating iterator function inside
display, meaning
display: function() {
var context = this;
function iteratorHelper() {..do something with context.var1..}
this.array1.each(iteratorHelper);
}
better in terms of performance than option 2? by using
this.array1.each(iteratorHelper.bind(this)) in display?
is bind bascially creating an object with the iterator function in
side, then extend the object with 'this'? if 'this' is a huge object,
then bind can take a long time right?
thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---