Unfamiliar with code syntax

49 views
Skip to first unread message

jeki...@prodigy.net

unread,
May 18, 2016, 12:36:32 AM5/18/16
to nodejs
Hello;
I have been doing browser javascript since 2003. I have also been doing php on the serverside. But I have become very interested in exploring node.js.

In the documentation on the Node.js site I see example code with constructs I am not familiar with:

sample 1 syntax
  fs.unlink('/tmp/hello', (err) => {
  if (err) throw err;
  console.log('successfully deleted /tmp/hello');
});

I am unfamiliare with "(err) =>". I have not seen this in javascript before

then there is:

sample 2 syntax
fs.watch('somedir', (event, filename) => {
  console.log(`event is: ${event}`);
  if (filename) {
    console.log(`filename provided: ${filename}`);
  } else {
    console.log('filename not provided');
  }
});

I am unfamiliar with this construct: "${event}".
I have seen this in php as variable variable references.
But this is not php. I was of the understanding that $ is
a valid and non special chararcter that can be used as
and identifier (although it shows up as the reference to
matches return from regex function)

Is there some published documentation that would clarify
and explain these constructs for me?

Thank you for time and attention.

PS I have successfully set up an http server with some elaborations based on
instructions from the Apress publication 'Beginning Node.js'

My set up services background requests of external css source files, image files
designated for background rules, and external javascript files. But I am uncertain
how an actuall "ajax" xmlHttpRequest object request would be handled from the
server's standpoint.

Thanks anew

JK

Duy Nguyen

unread,
May 18, 2016, 10:36:04 AM5/18/16
to nod...@googlegroups.com
Hi,

This is ES6 syntax, you can take a look at this guide http://es6-features.org/, section Arrow Functions.

I think this guide is easy to understand, they have comparison also between arrow and non-arrow function.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/1e621a81-3269-43f4-a985-5ced49124a69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Nguyen Hai Duy
Mobile : 0914 72 1900
Skype: nguyenhd2107

Emanuele DelBono

unread,
May 18, 2016, 10:36:23 AM5/18/16
to nod...@googlegroups.com
`event is: ${event}` is  equal to "event is: " + event
It's called string template or string interpolation and it is part of EcmaScript 2015 (ore ES6).
You can find a quick overview here: https://github.com/lukehoban/es6features

bye

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/1e621a81-3269-43f4-a985-5ced49124a69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jeki...@prodigy.net

unread,
May 19, 2016, 10:18:28 AM5/19/16
to nodejs

Thanks for responses; Dut Nguyen and Emanuele DelBono,  Your references have done a good job for me.

I would use stackOverflow for questions, but I managed to annoy someone to the point of being banned. I
also can't get answers to why for them.

JK
Reply all
Reply to author
Forward
0 new messages