Wednesday, May 28, 2014

JavaScript's Difficult Concepts - Notes

My Notes From: JavaScript's Difficult Concept
This is all Vanilla JavaScript.
Nothing about JQuery or MooTools or whatever.


Global vs Function
Always use **var** keyword when you name a variable inside a function.
Declare all variables at the top of your function.


The **this** keyword
callbacks are commonly used in JS???

The __this__ keyword and the context within the function depend entirely on how the function was invokes.

The default context will be the global context for functions invoked by name or variable name within the global context.

.call() is how you use __this__ properly. --> Switch the context of this.
.apply() is different.. allows more params??

Using .call and .apply gives you the control you might need over the context inside a function or method

The **ProtoType Chain**
"The most complicated inheritance model ever created"
Classless, Instance Based

// ** Use a Capital Letter for the function name as a Construction
function Person(name) {
    // blah
} = function() {
    return "wah";

Always use Function.prototype to add methods to your constructor functions for performance reasons.

// Extend the Person object
function Dev(name) {, name);
Developer.prototype = Object.create(Person.prototype); // Inherit
Developer.prototype.constructor = Developer; // Override constructor type

// Override = function() {
    return "wooo";

All Objects have the prototype through which we can accompolish inheritcan in JS


No comments:

Post a Comment