I don't quite follow your example: jQuery["attr"]("id")
I assume this is what you're speaking of: $("#identifier")["attr"]("id")
If so, is this not equivalent to $("#identifer")["id"]? Also, ["attr"] does
not appear to provide access to methods so it is not a replacement for
object['method-name'].call( object, parm, ... );
I realize that .callMethod() could be rewritten as:
jQuery.fn.callMethod = function( method )
{
try {
return eval("this."+ method );
}
catch (e) {
return this;
}
}
But we bar the use of eval() and consider it a security risk (or at least a
wildcard that we don't want to deal with). Using eval() the following could
be executed: $('#xyz').callMethod("hide();document.location.href='new url'")
.callMethod() using the parsing technique at least ensures that any
execution is limited to methods on the current jQuery collection.
The parameter passing deficiencies could be addressed with a bit morecode,
but for our purposes number conversion is sufficient.
-----Original Message-----
From: Dave Methvin [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 16, 2007 5:39 PM
To: 'jQuery Discussion.'
Subject: Re: [jQuery] .callMethod( method )
> I don't know if jQuery already has a way to do this (or if anyone else
> would find it useful), but here's a simple extension to call a method
> (with or with
> parameters) via a string.
Javascript lets you call a method directly with a string:
jQuery["attr"]("id") gets the id for example. Instead of passing a string of
arguments and parsing it you could just eval the attribute in the examples
you gave. Ad-hoc parsing often will get you into trouble; for example the
code you have will not process arglists that have strings with embedded
commas.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/