IDE suggested- Brackets by Adobe
JavaScript
NameSpace: A container for variables and functions. Typically to keep variables and functions with the same name separate.
First Class Functions: In java script functions are objects & they are first class funcitons. Every thing that you can do with other types can be done with functions. (assign them to variables, pass them as parameters annd create them on the fly.
Callback function - A function you give to other funciton, to be run when the other function is finished.
call(), apply(), method()
.bind creates a copy of what ever function you are calling and points 'this' variable to Object that you pass as parameter.
logName.bind(person);
Call()
func() and func.call() are same. It just invokes the function. However, with call() we can control the 'this' variable. Unlike bind, call() directly executes with out copying the function.
logName.call(person);
apply() is same as Call(). It just expects the parameters in Array rather than individual values.
Function Currying: Creating a copy of a function but with some preset parameters. This can be achieved by bind funciton passing the parameter values.
Inheritance in Java script: One object gets access to the properties and methods of another object.
Java script adds hidden method and proerties that we don't directly interact.
All Objects have proto {} property. It is a reference to another object called proto.
John and Person are two independent objects
John.__proto__=person will make person as parent of John
Except the base object(Object{}), every other object has the Prototype.
(one can find the proto by using a.__proto__ in console log)
Proto for function is function Empty(){} and Proto for Array is []. However, {} is proto for the Empty(){} & [].
Reflection: An object can look at itself, listing and changing its properties and methods.
eg: Suppose John is a Object. Following snippet will loop over its own members.
for (var prop in John){
console.log(prop + ": " + john[prop]);
}
Building Objects:
var obj=new functionObj();
The above statement creates empty object with 'this' pointing to it. It then copies the statements from funtion where ever 'this' is referred. (as long as the function doens't return any thing)
Also, functionObj() will be the Proto for obj.
Note: Prototype on function is not proto of the function. Rather it is proto of the Objects created using Function as constructor.
Object creation - method 2:
var obj=Object.create(Person);
This creates an empty object and its Prototype points to the Object that you pass as argument.
Github.com - to learn famous open source javascript code
Method Chaining: Calling one method after another, and each method affects the parent object.
eg: obj.method1().method2() where both methods end up with a 'this' variable pointing at 'obj'.
JavaScript
- It is a programming language Single threaded, synchronous programming language
- Object in javascript - It is a collection of name, value pair. However, value may be inturn name, value pair
Java script code is run inside execution context(Global). It creates Global Object(Window) & variable called 'this' which refers to Window object.
Variables and functions which are not inside a function are attached to GLOBAL Object.
Function Invocation and execution stack
Invocation in java script is by paranthesis
When ever a funtion is invoked, a new Execution context is created and placed on execution stack. And variable 'this' is pointed to respective execution stack
- var obj1=new Object()
- var obj2={}
NameSpace: A container for variables and functions. Typically to keep variables and functions with the same name separate.
First Class Functions: In java script functions are objects & they are first class funcitons. Every thing that you can do with other types can be done with functions. (assign them to variables, pass them as parameters annd create them on the fly.
Callback function - A function you give to other funciton, to be run when the other function is finished.
call(), apply(), method()
.bind creates a copy of what ever function you are calling and points 'this' variable to Object that you pass as parameter.
logName.bind(person);
Call()
func() and func.call() are same. It just invokes the function. However, with call() we can control the 'this' variable. Unlike bind, call() directly executes with out copying the function.
logName.call(person);
apply() is same as Call(). It just expects the parameters in Array rather than individual values.
Function Currying: Creating a copy of a function but with some preset parameters. This can be achieved by bind funciton passing the parameter values.
Inheritance in Java script: One object gets access to the properties and methods of another object.
Java script adds hidden method and proerties that we don't directly interact.
All Objects have proto {} property. It is a reference to another object called proto.
John and Person are two independent objects
John.__proto__=person will make person as parent of John
Except the base object(Object{}), every other object has the Prototype.
(one can find the proto by using a.__proto__ in console log)
Proto for function is function Empty(){} and Proto for Array is []. However, {} is proto for the Empty(){} & [].
Reflection: An object can look at itself, listing and changing its properties and methods.
eg: Suppose John is a Object. Following snippet will loop over its own members.
for (var prop in John){
console.log(prop + ": " + john[prop]);
}
Building Objects:
var obj=new functionObj();
The above statement creates empty object with 'this' pointing to it. It then copies the statements from funtion where ever 'this' is referred. (as long as the function doens't return any thing)
Also, functionObj() will be the Proto for obj.
Note: Prototype on function is not proto of the function. Rather it is proto of the Objects created using Function as constructor.
Object creation - method 2:
var obj=Object.create(Person);
This creates an empty object and its Prototype points to the Object that you pass as argument.
Github.com - to learn famous open source javascript code
Method Chaining: Calling one method after another, and each method affects the parent object.
eg: obj.method1().method2() where both methods end up with a 'this' variable pointing at 'obj'.
No comments:
Post a Comment