-1

I have a native javascript and some syntax don't mean anything to me. It's also hard to search on it on google. Possibly they are short term for something? (Its supposedly native js, no jquery)

What does this mean in these codes:

  • $.get = () => value();
  • return $; (what means the $ ?)
  • ((win, doc, name) => { ... }
Kenman
  • 11
  • 3

2 Answers2

0

The $ here is just like a normal JavaScript variable since $ is a valid character to define variable names.

  • $.get = () => value();: This code assigns an arrow function that calls the value function and immediately returns the result to the get property of $.

  • return $: returns the $ object at the end of some function.

  • (win, doc, name) => { ... } defines an arrow function with parameters named win, doc and name. The statements inside the curly braces is the body of the arrow function.

Kenneth
  • 30
  • 1
  • 4
-1
  • $.get = () => value();

This defines a method, get(), on the object $. The method, when called, simply calls a function, value(). It's a so-called arrow function - a short-form syntax for declaring functions that are bound to the current scope.

  • return $

This returns the value of $ from the current scope. It's impossible to say from what you've posted what the value of $ is.

  • ((win, doc, name) => { ... }

This is incomplete, and is currently a parse error. It too uses arrow syntax to declare a function. Judging by the opening bracket, it may be the start of an IIFE, or immediately-invoked function expression. The full form would be:

((win, doc, name) => { ... })(/* args here */)
Mitya
  • 30,438
  • 7
  • 46
  • 79