https://github.com/vikrantnegi/understanding-javascript-the-weird-parts-notes
Notes
https://github.com/vikrantnegi/understanding-javascript-the-weird-parts-notes
Last synced: 7 months ago
JSON representation
Notes
- Host: GitHub
- URL: https://github.com/vikrantnegi/understanding-javascript-the-weird-parts-notes
- Owner: vikrantnegi
- Created: 2018-05-05T15:32:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-05T16:07:46.000Z (over 8 years ago)
- Last Synced: 2025-02-14T08:18:37.417Z (over 1 year ago)
- Size: 382 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Understanding Javascript: The Weird Parts
### Functions
* Are special type of objects

### Function Statement
```
function greet(name) {
console.log("hello " + name);
}
```
### Function Expression
```
var greetFunc = function(name) {
console.log("Hello " + name);
}
```
* Function is not put into memory initially but during exceution
* JS engine create the function on the fly as soon it hits the line number
### IIFE - Immediately Invoked Function Expression
```
(function(name) {
console.log("Hello " + name);
}());
```
* First word of the function statement must be a function
* Wrapping function statement in a () tricks syntax parser to think it is a function expression and crates the object on the fly and invokes it, all at the same time.
* Creates its own extecution context so all variables inside it are isolated from outer environment.
### Closures
Watch Video
### .bind(), .apply(), call()
### .bind()
Creates a coy of whatever functions it is called on and object passed to it will be the refrence by
`this`
### Inheritance
One object get access to properties and methods of another object.
### Prototype
All objects have prototype property.
### Reflection and Extend
Reflection - An object can look ay itself, listening and changing its properties and methods.
### Function Constructors
* A normal function that is used to construct objects.
* The this variable points a new empty object, and that object is returned from the function automatically.
```
function Person(firstname, lastname) {
console.log(this);
this.firstname = firstname;
this.lastname = lastname;
console.log('This function is invoked.');
}
var john = new Person('John', 'Doe');
console.log(john);
var jane = new Person('Jane', 'Doe');
console.log(jane);
```