Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30814

Re: An "if" without "if"

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: An "if" without "if"
Date 2016-07-03 11:07 +0100
Organization A noiseless patient Spider
Message-ID <87y45j6nm0.fsf@bsb.me.uk> (permalink)
References <if-20160602002158@ram.dialup.fu-berlin.de> <nintrv$2uc$1@news.albasani.net> <nip29s$r1a$1@news.albasani.net> <nl9lap$sco$1@dont-email.me> <course-20160703072154@ram.dialup.fu-berlin.de>

Show all headers | View raw


ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Scott Sauyet <scott@sauyet.com> writes:
>>Stefan Weiss wrote:
>>>I have some doubts about the wisdom of introducing arrow functions and
>>>default arguments to a class before covering basics like if-else
>>>branching, but there may be a valid reason for this. 
>>Another very interesting work which proceeds the same way is Reg 
>>Braithwaite's _JavaScript Allongé_, either the original edition [1] or 
>>the ES6 one [2].
>
>   In the meantime, my course has finished, and I have learned
>   that for the goal of my beginner's course, which is to learn
>   event handling with JavaScript, I do not need neither
>   parameters nor default values nor the keyword »function«,
>   so, in the next course, I'll just explain parameterless
>   arrows only. For example, I'll explain
>
> ()=> 1
>
>   and slightly later I'll explain blocks, like, for example, in
>
> f = ()=> { console.log( "a" ); return 3; }
>
>   . Then, near the end of the short (18 hours) course,
>   I can show code like the following:
>
> onClick = () => span.classList.toggle( "off" );
>
> span = window.document.getElementById( "number" );
>
> window.document.getElementById( "brackets" ).
> addEventListener( "click", onClick );

Avoiding parameters seems like an odd choice:

  window.document.getElementById( "brackets" ).
  addEventListener( "click",
      (span => {return () => span.classList.toggle( "off" );})(
          window.document.getElementById( "number" ))
  );

-- 
Ben.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: An "if" without "if" andber93@web.de - 2016-06-02 02:16 +0200
  Re: An "if" without "if" Stefan Weiss <krewecherl@gmail.com> - 2016-06-02 12:37 +0200
    Re: An "if" without "if" Scott Sauyet <scott@sauyet.com> - 2016-07-03 00:13 +0000
      Re: An "if" without "if" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-03 11:07 +0100
      Re: An "if" without "if" "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-07-03 10:29 -0700
        Re: An "if" without "if" Scott Sauyet <scott@sauyet.com> - 2016-07-04 01:08 +0000
      Re: An "if" without "if" John Harris <niam@jghnorth.org.uk.invalid> - 2016-07-04 14:49 +0100

csiph-web