| If used in a constructor function for an object created with "new": | It refers to the newly created object. |
| If used in the global scope: | this refers to the global scope. |
| If this is used in a function: | this refers to the function's parent scope. |
| If the function is a member of an object: | this refers to the object. |
| If a global reference is made to a member function then invoked: | this in the function refers to the global scope. |
| In an event handler: | this refers to the element the event was emitted by. |
| If you invoke func() with func.call(someThis, arg1, arg2, ...): | in func() this refers to the passed first argument. |
| If you invoke func() with func.apply(someThis, [...]): | In func this refers to the context of someThis. Apply does the same thing as call. The only difference is that Apply takes its arguments as an array. |
Example Syntax:
(arg1, arg2, ..., argN) => { statements }
(arg1, arg2, ..., argN) => expression /* equivalent to return expression */
singleArg => expression
Example use in code:
var people = ["Fawett", "Bhosale", "Salman", "Corley", "Cui" ];
people.map(person => person.length); returns Array[6, 7, 6, 6, 3];
Note:
The array.map(function(currentValue)) returns a new array with values that are returned by the input function
when applied to each element of the original array. Yes, functions can be passed as arguments to other functions.
<script>
showvalue('CreateFunction.funName = "Joe"');
CreateFunction.funName = "Joe";
showline('CreateFunction.age = "20 minutes"');
CreateFunction.age = "20 minutes";
showvalue("my funName is " + CreateFunction.funName);
showline("my age is " + CreateFunction.age);
showvalue("showing all JSon");
showvalue("----------------")
showAllJSon(CreateFunction);
putline();
showvalue("invoking function");
showvalue("-----------------");
CreateFunction()();
</script>