Hi,

I'm unable to get the invoke method to work inside an instance of an
object, when the method I'm trying to invoke needs the 'this' keyword
in order for the method to be identified.

Example:
var myClass = Class.create();
myClass.prototype = {
  intialize:function() {
    // ...do stuff
  },
  getRows:function() {
    // invoke using this.setupRow doesn't work
    $$('.rows').invoke('this.setupRow').bind(this);
  },
  setupRow:function(row) {
    // ...do stuff to row
  }
}
var myClassI = new myClass();

---------------------------------------------------
In the above example, when I attempt to use invoke to call a method
inside the object, it doesn't work.  I've tried without bind, and I've
tried moving bind around to everywhere I could think of, and not using
single quotes:
$$('.rows').invoke('this.setupRow.bind(this)');
$$('.rows').invoke(this.setupRow.bind(this));
$$('.rows').invoke(this.setupRow).bind(this);
$$('.rows').invoke(this.setupRow);
etc, etc

I managed a simple workaround, but it's using Enumerable#each instead
of Enumerable#invoke.  It isn't the end of the world, but if it's
possible to use the more efficient invoke method, I'd much prefer it.
workaround:
$$('.rows').each(function(row) {this.setupRow(row);}.bind(this);

Some things to note.  Looking at the invoke method in prototype.js, it
uses 'this', which refers to the page in my example.  I think it's not
supposed to work like I'm trying to use it.  But, I don't want to jump
to conclusions if anyone else knows differently.
The 'this' keyword is properly referring to my instance of myClass
within the getRows() method.  I verified this several ways, but
probably most importantly using firebug in firefox.
The JS error that I receive is:
TypeError: value[method] has no properties  line 708
prototype version: 1.6.0.1
If I use invoke to call a method like 'hide' or any other global scope
method, it works fine.

As I said, I have a suitable workaround, but I'm just not sure why
invoke isn't working like I expect it to here.  Am I doing it wrong?
Is it not supposed to work this way?  Or is it a bug?

Thanks for any help.
Knox
--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-spinoffs@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to