Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

One person's error is another person's data.


devel / comp.lang.javascript / Re: removing event listener

SubjectAuthor
* removing event listenerAndrew Poulos
+* Re: removing event listenerBen Bacarisse
|`- Re: removing event listenerThomas 'PointedEars' Lahn
+* Re: removing event listenerJulio Di Egidio
|+* Re: removing event listenerJJ
||`- Re: removing event listenerJulio Di Egidio
|+* Re: removing event listenerJohn Harris
||`* Re: removing event listenerJulio Di Egidio
|| `- Re: removing event listenerJohn Harris
|`- Re: removing event listenerJohn Harris
`- Re: removing event listenerThomas 'PointedEars' Lahn

1
removing event listener

<8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17338&group=comp.lang.javascript#17338

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!nntp.westnet.com.au!news.westnet.com.au.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 10 Oct 2021 18:37:38 -0500
Newsgroups: comp.lang.javascript
X-Mozilla-News-Host: news://news.iinet.net.au:119
From: ap_prog@hotmail.com (Andrew Poulos)
Subject: removing event listener
Date: Mon, 11 Oct 2021 10:37:37 +1100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-AU
Content-Transfer-Encoding: 7bit
Message-ID: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
Lines: 22
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 203.219.129.187
X-Trace: sv3-dzKupx+gXsUFzBEBWeK2O+snsfRAnYGcmnmYnC0xnXaOcYm4k/j/h96LnSHGW4w106EvO+Cx1qrvmx4!a9MhKWawu4VrT3GLpXE/qMIUSCUWRYQ9k4yMKLIDwbLgCCG9Mb1S0Rw9ftaZ+agZ6bmz+pF/INA7!FmFBv1rxeR/H8agP7Cc1ypY=
X-Complaints-To: abuse@westnet.com.au
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1653
 by: Andrew Poulos - Sun, 10 Oct 2021 23:37 UTC

I Have this

Interaction = function() {
...
};

Interaction.prototype.action = function() {
let me = this;
...
document.addEventListener('keydown', me.action.bind(me));
};

Interaction.prototype.reaction = function() {
let me = this;
...
document.removeEventListener('keydown', me.action.bind(me));
};

but when 'reaction' gets called the 'keydown' event listener doesn't get
removed. How can I remove the event listener within 'reaction'?

Andrew Poulos

Re: removing event listener

<87ee8rbmap.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17339&group=comp.lang.javascript#17339

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.javascript
Subject: Re: removing event listener
Date: Mon, 11 Oct 2021 16:42:22 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <87ee8rbmap.fsf@bsb.me.uk>
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="21a644e6b7b9371e1c94688240884ca4";
logging-data="21461"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nqvBo9u4ZKBWabTfRiw45WVwhnQ+yUwA="
Cancel-Lock: sha1:bQkc+MtGBt+RYgho5pOV8jw8dy8=
sha1:LTgdpAqe29S+9HQMEQXKu9PYHQk=
X-BSB-Auth: 1.5a9cf2203d88734dcfdd.20211011164222BST.87ee8rbmap.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 11 Oct 2021 15:42 UTC

Andrew Poulos <ap_prog@hotmail.com> writes:

> I Have this
>
> Interaction = function() {
> ...
> };
>
> Interaction.prototype.action = function() {
> let me = this;
> ...
> document.addEventListener('keydown', me.action.bind(me));
> };
>
> Interaction.prototype.reaction = function() {
> let me = this;
> ...
> document.removeEventListener('keydown', me.action.bind(me));
> };
>
> but when 'reaction' gets called the 'keydown' event listener doesn't
> get removed. How can I remove the event listener within 'reaction'?

bind creates a new anonymous function but you can only remove an event
function by passing in the exact same function you passed when calling
addEventListener. You'll have to store that function value somewhere.

--
Ben.

Re: removing event listener

<539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17340&group=comp.lang.javascript#17340

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:6214:921:: with SMTP id dk1mr25028966qvb.54.1633970792198;
Mon, 11 Oct 2021 09:46:32 -0700 (PDT)
X-Received: by 2002:aca:b186:: with SMTP id a128mr48242oif.48.1633970791916;
Mon, 11 Oct 2021 09:46:31 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Mon, 11 Oct 2021 09:46:31 -0700 (PDT)
In-Reply-To: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
Injection-Info: google-groups.googlegroups.com; posting-host=93.41.100.170; posting-account=F3H0JAgAAADcYVukktnHx7hFG5stjWse
NNTP-Posting-Host: 93.41.100.170
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>
Subject: Re: removing event listener
From: julio@diegidio.name (Julio Di Egidio)
Injection-Date: Mon, 11 Oct 2021 16:46:32 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 14
 by: Julio Di Egidio - Mon, 11 Oct 2021 16:46 UTC

On Monday, 11 October 2021 at 14:07:33 UTC+2, Andrew Poulos wrote:

> Interaction.prototype.action = function() {
> let me = this;
> ...
> document.addEventListener('keydown', me.action.bind(me));
> };

Calling itself? You sure it is not that the problem?

Also, directly 'this' instead of 'me' would work fine in that case.

Also, Ben is incorrect: the match must be lexical, not by reference (JS is a functional language...).

Julio

Re: removing event listener

<10ysg4pgzm4b9.s3luwgx38g19.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17341&group=comp.lang.javascript#17341

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!i2pn.org!aioe.org!IsjeSeFEaX8LPqsGNOmS1Q.user.46.165.242.91.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.lang.javascript
Subject: Re: removing event listener
Date: Tue, 12 Oct 2021 22:21:12 +0700
Organization: Aioe.org NNTP Server
Message-ID: <10ysg4pgzm4b9.s3luwgx38g19.dlg@40tude.net>
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au> <539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="54156"; posting-host="IsjeSeFEaX8LPqsGNOmS1Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: 40tude_Dialog/2.0.15.84
X-Notice: Filtered by postfilter v. 0.9.2
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
 by: JJ - Tue, 12 Oct 2021 15:21 UTC

On Mon, 11 Oct 2021 09:46:31 -0700 (PDT), Julio Di Egidio wrote:
>
> Also, Ben is incorrect: the match must be lexical, not by reference (JS is
> a functional language...).

No. Ben is correct.

As long any of the argument is different when passed to
`removeEventListener()` than when passed to `addEventListener()` (i.e. not
exact match of argument set), the event handler will never be removed.

The only exception is when the third argument (the options) is an object
when adding an event listener. The object reference doesn't need to match
when the event listener is to be removed.

Re: removing event listener

<935ae9fc-5953-4899-8ff9-75420b75336an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17342&group=comp.lang.javascript#17342

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a0c:e10b:: with SMTP id w11mr31651203qvk.33.1634057846922;
Tue, 12 Oct 2021 09:57:26 -0700 (PDT)
X-Received: by 2002:aca:d78b:: with SMTP id o133mr4392228oig.136.1634057846697;
Tue, 12 Oct 2021 09:57:26 -0700 (PDT)
Path: rocksolid2!news.neodome.net!feeder1.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Tue, 12 Oct 2021 09:57:26 -0700 (PDT)
In-Reply-To: <10ysg4pgzm4b9.s3luwgx38g19.dlg@40tude.net>
Injection-Info: google-groups.googlegroups.com; posting-host=93.41.99.195; posting-account=F3H0JAgAAADcYVukktnHx7hFG5stjWse
NNTP-Posting-Host: 93.41.99.195
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
<539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com> <10ysg4pgzm4b9.s3luwgx38g19.dlg@40tude.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <935ae9fc-5953-4899-8ff9-75420b75336an@googlegroups.com>
Subject: Re: removing event listener
From: julio@diegidio.name (Julio Di Egidio)
Injection-Date: Tue, 12 Oct 2021 16:57:26 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2074
 by: Julio Di Egidio - Tue, 12 Oct 2021 16:57 UTC

On Tuesday, 12 October 2021 at 17:22:00 UTC+2, JJ wrote:
> On Mon, 11 Oct 2021 09:46:31 -0700 (PDT), Julio Di Egidio wrote:
> >
> > Also, Ben is incorrect: the match must be lexical, not by reference (JS is
> > a functional language...).
>
> No. Ben is correct.

No, he wasn't, what I said is precise (about the thing and about what was said): while you are simply being a super sloppy trolling ass.

Usenet is a shithole...

*Plonk*

Julio

> As long any of the argument is different when passed to
> `removeEventListener()` than when passed to `addEventListener()` (i.e. not
> exact match of argument set), the event handler will never be removed.
>
> The only exception is when the third argument (the options) is an object
> when adding an event listener. The object reference doesn't need to match
> when the event listener is to be removed.

Re: removing event listener

<e109b0fa-e397-4fe5-351b-b65f84f35ec2@jghnorth.org.uk.invalid>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17343&group=comp.lang.javascript#17343

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: niam@jghnorth.org.uk.invalid (John Harris)
Newsgroups: comp.lang.javascript
Subject: Re: removing event listener
Date: Tue, 12 Oct 2021 18:13:32 +0100
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <e109b0fa-e397-4fe5-351b-b65f84f35ec2@jghnorth.org.uk.invalid>
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
<539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>
Reply-To: jgharris@ic4life.net
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="99c6e08296f787988484bb53a5c93a98";
logging-data="32376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ag62jfAMLZVzP51BhwW0gbSbJNqYkfz0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:LAkZEZ9u7mj8NePV+52uHsWx1dI=
In-Reply-To: <539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>
Content-Language: en-US
 by: John Harris - Tue, 12 Oct 2021 17:13 UTC

On 11/10/2021 17:46, Julio Di Egidio wrote:

<snip>
> (JS is a functional language...).

The ECMAScript standard, ECMA-262 11th Edition/June 2020, doesn't say
that, so you can't rely on that to tell you the way a program will work.

John

Re: removing event listener

<sk4fro$vjo$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17344&group=comp.lang.javascript#17344

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: niam@jghnorth.org.uk.invalid (John Harris)
Newsgroups: comp.lang.javascript
Subject: Re: removing event listener
Date: Tue, 12 Oct 2021 18:15:35 +0100
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <sk4fro$vjo$2@dont-email.me>
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
<539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>
Reply-To: jgharris@ic4life.net
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Oct 2021 17:15:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="99c6e08296f787988484bb53a5c93a98";
logging-data="32376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19S8Mdiqfc3cRr1W73XHTi7WLG2vMpPDV0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:k3AstxhIZJJxQ33li1JHMQMKrs8=
In-Reply-To: <539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>
Content-Language: en-US
 by: John Harris - Tue, 12 Oct 2021 17:15 UTC

On 11/10/2021 17:46, Julio Di Egidio wrote:

<snip>> (JS is a functional language...).

The ECMAScript standard, ECMA-262 11th Edition/June 2020, doesn't say
that, so you can't rely on that to tell you the way a program will work.

John

Re: removing event listener

<2010902.KlZ2vcFHjT@PointedEars.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17345&group=comp.lang.javascript#17345

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!news.neodome.net!feeder.usenet.ee!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.178.197.213.235!not-for-mail
From: PointedEars@web.de (Thomas 'PointedEars' Lahn)
Newsgroups: comp.lang.javascript
Subject: Re: removing event listener
Date: Tue, 12 Oct 2021 22:43:30 +0200
Organization: PointedEars Software (PES)
Lines: 12
Message-ID: <2010902.KlZ2vcFHjT@PointedEars.de>
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au> <87ee8rbmap.fsf@bsb.me.uk>
Reply-To: Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7Bit
Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.213.235";
logging-data="657919"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: KNode/4.14.10
Cancel-Lock: sha1:kUd48yYkKZjVr2PmHQb0XtrsdeM=
X-User-ID: U2FsdGVkX19DoOIGHn2cVJovMFKNWEvyYJZohGteHOq+PB/a6Ebrjw==
Face: iVB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<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
 by: Thomas 'Pointed - Tue, 12 Oct 2021 20:43 UTC

Ben Bacarisse wrote:

> bind creates a new anonymous function but you can only remove an event
> function by passing in the exact same function you passed when calling
> addEventListener. You'll have to store that function value somewhere.

The _reference to_ that Function _instance_ (object).

--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Re: removing event listener

<2529056.k3LOHGUjKi@PointedEars.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17346&group=comp.lang.javascript#17346

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!i2pn.org!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.178.197.213.235!not-for-mail
From: PointedEars@web.de (Thomas 'PointedEars' Lahn)
Newsgroups: comp.lang.javascript
Subject: Re: removing event listener
Date: Tue, 12 Oct 2021 22:55:18 +0200
Organization: PointedEars Software (PES)
Lines: 59
Message-ID: <2529056.k3LOHGUjKi@PointedEars.de>
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
Reply-To: Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8Bit
Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.213.235";
logging-data="659573"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: KNode/4.14.10
Cancel-Lock: sha1:k8HkxkEPDrAbsC6ZfPM65XfVXD4=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1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'Pointed - Tue, 12 Oct 2021 20:55 UTC

Andrew Poulos wrote:

> Interaction = function() {

This should be

let Interaction = function () {

> ...
> };
>
> Interaction.prototype.action = function() {
> let me = this;

This workaround is not necessary if you are using Function.prototype.bind()
anyway, although referring to the “this” value by “me” instead of “this”
might be more efficient.

> ...
> document.addEventListener('keydown', me.action.bind(me));

Change this line to

let keyDown = me.keyDown = me.action.bind(me);
document.addEventListener('keydown', keyDown);

or something similar,

> };
>
> Interaction.prototype.reaction = function() {
> let me = this;
> ...
> document.removeEventListener('keydown', me.action.bind(me));

and this line to

document.removeEventListener('keydown', me.keyDown);

respectively.

You should consider whether the document object really is the right object
to listen to the event, or if, for example, the object referred to by
“document.body” is more appropriate. In general, you should add event
listeners for bubbling events as deep in the DOM tree as is feasible,
to avoid unwanted side effects.

> };
>
> but when 'reaction' gets called the 'keydown' event listener doesn't get
> removed. How can I remove the event listener within 'reaction'?

It is perhaps a good idea to define a method that handles the “keydown”
event (listener) exclusively for the instance that inherits that method.

--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Re: removing event listener

<4a2573d5-823c-4564-aed3-c28c4512c4ean@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17347&group=comp.lang.javascript#17347

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ac8:7e96:: with SMTP id w22mr11950385qtj.28.1634079918446;
Tue, 12 Oct 2021 16:05:18 -0700 (PDT)
X-Received: by 2002:a9d:69c9:: with SMTP id v9mr27784247oto.127.1634079918222;
Tue, 12 Oct 2021 16:05:18 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Tue, 12 Oct 2021 16:05:17 -0700 (PDT)
In-Reply-To: <e109b0fa-e397-4fe5-351b-b65f84f35ec2@jghnorth.org.uk.invalid>
Injection-Info: google-groups.googlegroups.com; posting-host=93.41.99.195; posting-account=F3H0JAgAAADcYVukktnHx7hFG5stjWse
NNTP-Posting-Host: 93.41.99.195
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
<539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com> <e109b0fa-e397-4fe5-351b-b65f84f35ec2@jghnorth.org.uk.invalid>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4a2573d5-823c-4564-aed3-c28c4512c4ean@googlegroups.com>
Subject: Re: removing event listener
From: julio@diegidio.name (Julio Di Egidio)
Injection-Date: Tue, 12 Oct 2021 23:05:18 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 14
 by: Julio Di Egidio - Tue, 12 Oct 2021 23:05 UTC

On Tuesday, 12 October 2021 at 19:13:39 UTC+2, John Harris wrote:
> On 11/10/2021 17:46, Julio Di Egidio wrote:
>
> <snip>
> > (JS is a functional language...).
> The ECMAScript standard, ECMA-262 11th Edition/June 2020, doesn't say
> that, so you can't rely on that to tell you the way a program will work.

The case in point was "the match must be lexical, not by reference", which of course you can't even parse even less understand the import of, and which of course is the thing that is documented, just not in those high-level words.

Indeed, I might put together, maybe in the w-e, a little example with "lexical matching": not for you obnoxious asshole, but others around here might even learn something, what what I said means to begin with...

(EOD.)

Julio

Re: removing event listener

<sk73un$lfc$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17348&group=comp.lang.javascript#17348

  copy link   Newsgroups: comp.lang.javascript
Path: rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: niam@jghnorth.org.uk.invalid (John Harris)
Newsgroups: comp.lang.javascript
Subject: Re: removing event listener
Date: Wed, 13 Oct 2021 18:10:47 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <sk73un$lfc$1@dont-email.me>
References: <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au>
<539fdb3e-7889-4ee1-9492-430ebe78b0d3n@googlegroups.com>
<e109b0fa-e397-4fe5-351b-b65f84f35ec2@jghnorth.org.uk.invalid>
<4a2573d5-823c-4564-aed3-c28c4512c4ean@googlegroups.com>
Reply-To: jgharris@ic4life.net
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 13 Oct 2021 17:10:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ea25cdf2ee86b88f7f00d85ca8225e90";
logging-data="21996"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XbOJGrRdc8roxcoLK8toWQPX++oJYKjU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:MJaAVfbhHuKUKlPMI8B0yvV6o4Y=
In-Reply-To: <4a2573d5-823c-4564-aed3-c28c4512c4ean@googlegroups.com>
Content-Language: en-US
 by: John Harris - Wed, 13 Oct 2021 17:10 UTC

On 13/10/2021 00:05, Julio Di Egidio wrote:
> On Tuesday, 12 October 2021 at 19:13:39 UTC+2, John Harris wrote:
>> On 11/10/2021 17:46, Julio Di Egidio wrote:
>>
>> <snip>
>>> (JS is a functional language...).
>> The ECMAScript standard, ECMA-262 11th Edition/June 2020, doesn't say
>> that, so you can't rely on that to tell you the way a program will work.
>
> The case in point was "the match must be lexical, not by reference", which of course you can't even parse even less understand the import of, and which of course is the thing that is documented, just not in those high-level words.
<snip>

I'm glad to see you agree with me.

John


devel / comp.lang.javascript / Re: removing event listener

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor