Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #11963
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Jake Jarvis <pig_in_shoes@yahoo.com> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: onclick=function(){obj.meth()} |
| Date | Mon, 20 Feb 2012 22:38:22 +0100 |
| Lines | 69 |
| Message-ID | <9qfsqeF75tU1@mid.uni-berlin.de> (permalink) |
| References | <jp45k75qbcjbb5v8tavnmognds11hjihdh@4ax.com> <jhu992$b78$1@news.albasani.net> <1fb5k75j7mbjn04fm251o1omb0u1l1rbqv@4ax.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de Z8AWO6lMVGZ4mORQnOhzKw3KlUZq+8yTIKNnJyaG8scNk9Evk= |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 |
| In-Reply-To | <1fb5k75j7mbjn04fm251o1omb0u1l1rbqv@4ax.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.javascript:11963 |
Show key headers only | View raw
On 20.02.2012 21:47, Puzzled wrote:
> On Mon, 20 Feb 2012 21:09:05 +0100,
> Stefan Weiss<krewecherl@gmail.com> wrote:
>
>> On 2012-02-20 20:02, Puzzled wrote:
>>> Now I'm trying to convert the code to javascript's version of oo
>>> style
>> ...
>>> function row( i )
>>> {
>>> var rec_s = '<tr><td><a href="javascript:void(0);" '+
>>> 'id="foo'+i+'" '+
>>> 'onclick=function(){alert('+i+')}>'+i+'</a>'+
>>> '</td></tr>';
>>> return rec_s ;
>>> }
>>
>> Why are you wrapping "function(){ ... }" around your event handler code?
>> That's not what "javascript's version of oo style" is. Anonymous
>> functions have their place, but they need to be part of an expression,
>> or it's syntax error. Drop the "function(){ ... }" bit (and put the
>> remaining onclick value in quotes, while you're at it).
>>
>> There are some other weak spots in your code, but this should resolve
>> the syntax error.
>
> What I supplied was the simplest form that gives the error. What
> I'm actually trying to do is use a method as the event service
> routine, so a somewhat more accurate version of the code would
> be:
>
> // row is called as x.rec_row,
> // where x is the obj instance identifier
>
> // esr is the event service routine declared in x
>
> // i is the integer id of the record that can be selected
> // for further processing by clicking the link
>
> function row( i )
> {
> var proxy = this ; // create a closure-alias for 'this'
> var rec_s = '<tr><td><a href="javascript:void(0);" '+
> 'id="foo'+i+'" '+
> 'onclick=function(){proxy.esr(i)}>'+i+'</a>'+
> '</td></tr>';
> return rec_s ;
> }
>
> It's my understanding that to use a method as an esr, I've to
> create and use a proxy for 'this' in the event binding as here,
> and use an anon function so as to be able to pass arguments. Is
> that not so?
When you use HTML "intrinsic event attributes" you write as attribute
content the statements you want executed
<a onclick="p.esr(2);">2</a>
(note the delimiting with " (details in the HTML specs))
When you script the HTML document by manipulating the higher level DOM
representation you assign an anonymous function
anchorRef.onclick = function () { p.esr(2); };
--
Jake Jarvis
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 14:02 -0500
Re: onclick=function(){obj.meth()} "Tom de Neef" <tdeneef@qolor.nl> - 2012-02-20 20:20 +0100
Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 20:39 +0100
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:34 +0000
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:13 +0100
Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:05 -0800
Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:47 +0100
Re: onclick=function(){obj.meth()} John G Harris <john@nospam.demon.co.uk> - 2012-02-21 15:59 +0000
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 21:09 +0100
Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-20 20:29 +0000
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 16:50 -0500
Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-21 11:33 +0000
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 15:47 -0500
Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 22:38 +0100
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:12 -0500
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 14:04 -0800
"The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 01:37 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) Gene Wirchenko <genew@ocis.net> - 2012-02-20 17:20 -0800
Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:44 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 22:31 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-22 10:55 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) John G Harris <john@nospam.demon.co.uk> - 2012-02-22 15:58 +0000
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:30 +0000
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-20 13:43 -0800
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 23:17 +0100
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:48 -0500
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 00:57 +0100
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:03 +0000
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 19:05 -0800
Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:14 -0800
Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:54 +0100
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 10:17 -0800
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:57 -0800
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 13:39 -0800
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-22 05:07 -0800
Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:58 +0100
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:45 +0000
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:22 +0100
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-21 08:12 -0500
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:14 -0800
csiph-web