the keyword “this” of javascript
sometimes, it is not obvious to know what the keyword "this" refers to when you come across in the javascript. true, but when you step back and look into the key concept, it is as simple as the keyword "this" always belongs to the object that the containing function is a method of. take a look in the below example.
javascript# – scope and scope chain
Each execution context has an assigned scope when created. A scope can be thought of as an “object” that is associated with a particular execution context (this scope object is actually the Activation Object we mentioned above). A scope chain consists of a list (or chain) of such objects. The scope chain of an execution context is a chain of objects with the current “scope” object on the top, the “scope” object of the calling execution context as the 2nd object on the top, and so on, with the last “scope” object of the chain being that of the global execution context.
What do scope and scope chain do? They are used for variable resolution. When some JavaScript refers to a variable "foo", the host environment will try to resolve this variable. This resolution process is against the scope chain of the current execution context. First, it will search to see if there is a variable with the same name in the current scope. This is done by checking to see if the current “scope” object has such a named property. Remember that we mentioned Activation Object and Variable Object are the same object, and local variables (including inner function declarations, and function arguments) are instantiated as named properties of the Variable object during variable instantiation. So if the “foo” variable is defined in the local execution context, there must be a property of the Variable object named “foo”. If such a named property is not found, it means this “foo” variable is not defined here. The resolution process will now go down the scope chain and check against the 2nd “scope” object and so on until such such a named property is found or otherwise an “undefined” error happens
(BTW: Prototype chain is always part of property resolution process and no difference here either. The normal prototype chain lookup process applies when looking for a property with a specific name from a “scope” object: If no such property is found on the object itself, the prototype object will be searched. Still not found, the prototype of the prototype object will be searched. Until either the property is found or the end of the prototype chain is reached).
Important to point out: each function object has an internal property called [[scope]] (see more info on this later in this post) that consists of a list (or chain) of objects. This [[scope]] property can not be directly referenced by JavaScript code. When the function object is created, its internal [[scope]] property is assigned to the execution context in which this function object is created. This execution context has its own scope object and so on. In the end, the [[scope]] property is associated with a scope chain with the execution context in which the function object is created being on the top.
The scope chain of the execution context of a function call consists of the list referred to by the [[scope]] property of the corresponding function object and the Activation object created for this function call. The activation object is at the front of the chain (or the top of the list).
Along with the javascript #4, the execution context can be depicted as follows
- Execution Context
- Activation object = Variable object
- arguments object = function's formal parameteres
- local variables
- inner function objects
- arguments object = function's formal parameteres
- scope = Activation object
- scope chain = Activation object + the chain referred to by the [[scope]] property of this function object.
- Activation object = Variable object
- reference - http://ajax.sys-con.com/node/676031
javascript# – variable object and variable initialization
ECMA Specification refers to a “Variable Object” for variable instantiation. “Variable Instantiation” is a process that takes place when the JavaScript host environment processes a piece of script so that it can be executed but before executing the script. In this process, the JavaScript engine prepares(”instantiates”) the local variables, local functions declarations, and arguments to the function call etc. so that these variables are accessible during execution.
The way that variable instantiation works is to instantiate each of the function’s formal parameters, local variables and inner function declarations as named properties of the Variable Object. In the process, named properties of the Variable object are created for each of the function’s formal parameters. If arguments to the function call correspond with those parameters, the values of those arguments are assigned to the properties (otherwise the assigned value is undefined). If there is an inner function declaration, a function object is created. This function object is assigned a property of the Variable object with name corresponding to the function name used in the function declaration. The last stage of variable instantiation is to create named properties of the Variable object that correspond with all the local variables declared within the function.
The properties created on the Variable object that correspond with declared local variables are initially assigned undefined values during variable instantiation, the actual initialization of local variables does not happen until the evaluation of the corresponding assignment expressions during the execution of the function body code.
So the full pictures of object is depicted as follows
- Execution Context
- Activation object = Variable object
- arguments object = function's formal parameteres
- local variables
- inner function objects
- arguments object = function's formal parameteres
- Activation object = Variable object
However, it is very important to point out that the Activation object is used as the Variable object. Though conceptually they are called out as different objects, they are the same object in reality. This is important as you can see quickly in “scope and scope chain” and “variable resolution” later on.
It is the fact that the Activation object, with its arguments property, and the Variable object, with named properties corresponding with function local variables, are the same object, that allows the identifier arguments to be treated as if it were a function local variable.
- reference - http://ajax.sys-con.com/node/676031
javascript# – activation object
When an execution context is created, an Activation Object is created. The Activation Object can be considered as a normal JavaScript object with accessible named properties, except that it has no prototype and it cannot be directly referenced by javaScript code.This Activation Object is used for storing context related information such as call arguments and variables, etc. so that they are accessible to the new execution context (see more info on this later in this post).
javascript# – execution context
An execution context is an abstract concept used by the EcmaScript specification and can be conceived (and even implemented) as a set of objects with properties, though not publicly accessible, that encapsulate the context in which a piece of JavaScript code executes. The JavaScript code would rely on its execution context for things like variable resolution and scoping.
All JavaScript code executes in an execution context. Global code (code executed inline, normally as a JS file, or HTML page, loads) gets executed in a global execution context (in a browser, the global context is typically the window object), and each invocation of a function (possibly as a constructor) has an associated execution context. Code executed with the eval and setTimeout functions also gets a distinct execution context.
When a JavaScript function is called, it enters an execution context. If another function is called (or the same function recursively), a new execution context is created and execution enters that context for the duration of the function call. When that called function returns, control returns to the original execution context and the just finished execution context is available for garbage collection except for cases like closure. Thus running JavaScript code forms a stack of execution contexts.
javascript# – object.prototype
whenever you create the object/function in the javascript (except the primitive type), it is actually the creation of Object object. when you look deep into the object, there is a argument prototype, in which helps you to define the definition of the object and the way to traserve the object chain.
javascript closure revisit
what thing should i revisit when i come to the design of something using the javascript again, the following statement always come to my mind, as they are really the hardcore skill / concept should be understood when you are going to code the javascript in modern browser.
"The simple explanation of a Closure is that ECMAScript allows inner functions; function definitions and function expressions that are inside the function bodes of other functions. And that those inner functions are allowed access to all of the local variables, parameters and declared inner functions within their outer function(s). A closure is formed when one of those inner functions is made accessible outside of the function in which it was contained, so that it may be executed after the outer function has returned. At which point it still has access to the local variables, parameters and inner function declarations of its outer function. Those local variables, parameter and function declarations (initially) have the values that they had when the outer function returned and may be interacted with by the inner function."
agree or not?
outliners – the story of success

just hang around the book store and got this book - outliners, the story of success from Malcolm Gladwell. yes, i worth check it out.
google chrome – tab is a separate process, not only for performance
when you are going to play with the google browser chrome's tab feature, you would find that each tab is of separate process when you are looking into the task manager of the windows (or some equivalent operating system). truely, the first benefit gets from it is - one process won't crash the other if there is some problems from the page, but i am not interested on it.
what i am interested in is of security! basically, for each different processes, the operating system would allocate different memory spaces for each process, so theoritically, different tab would be served as different application instance (process) in which they cannot access each other resources, like the memory space, DOM etc. so google browser chrome is actually making a very fundamental change in the software architecture of the web applications with this unnoticed features.

- reference - http://www.google.com/chrome
amazon web services cloud to enterprise ready

amazon web services announced a virtual private cloud service to limited public beta, it definitely a move to provide cloud services for enterprises. the amazon virtual private cloud would bridge the company's existing IT infrastructure and the AWS cloud (based on EC2) through the virtual private network connection, so as to extend their existing management capabilities.




































