Hi there, I would like to start my Ninja Techniques posts making a general introduction of the main Javascript features I’ll talk about that are not tipically explained in most of the Javascript books, plus the concept of execution context.
Note: Most of the info in Ninja Techniques posts are based on the wonderful posts these guys;
- http://perfectionkills.com
- http://www.nczonline.net
- http://javascriptweblog.wordpress.com
- http://allyoucanleet.com
- http://dmitrysoshnikov.com
had written, together with the Standard ECMA-262.
First of all, Javascript is an implementation of the ECMAScript language.
ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects within a host environment. ECMAScript as defined here is not intended to be computationally self-sufficient; indeed, there are no provisions in this specification for input of external data or output of computed results. Instead, it is expected that the computational environment of an ECMAScript program will provide not only the objects and other facilities described in this specification but also certain environment-specific host objects, whose description and behaviour are beyond the scope of this specification except to indicate that they may provide certain properties that can be accessed and certain functions that can be called from an ECMAScript program.
Let’s take a look at some definitions directly from the ECMAScript standard:
- type:
An ECMAScript language type corresponds to values that are directly manipulated by an ECMAScript programmer using the ECMAScript language. The ECMAScript language types are Undefined, Null, Boolean, String, Number, and Object.
- primitive value:
member of one of the types Undefined, Null, Boolean, Number, or String as defined in Clause 8 (types definition).
e.g. “hola”, 1, true etc.
- object:
member of the type Object.
e.g. var a = new Array();
- constructor:
Function object that creates and initialises objects.
e.g. Array
- prototype:
object that provides shared properties for other objects.
e.g. Array.prototype
- native object:
object in an ECMAScript implementation whose semantics are fully defined by this specification rather than by the host environment.
Some native objects are built-in; others may be constructed during the course of execution of an ECMAScript program.
- built-in object:
object supplied by an ECMAScript implementation, independent of the host environment, that is present at the start of the execution of an ECMAScript program.
e.g. Math
One, the global object, is part of the lexical environment of the executing program. Others are accessible as initial properties of the global object. Every built-in object is a native object.
- host object:
object supplied by the host environment to complete the execution environment of ECMAScript.
e.g. window
- etc. (See all definitions here)
Conclusion got from these definitions:
Javascript is an implementation of something more general and platform independent! Ok, this we knew it. And there are entities which behaviour and features are defined by the standard and other kind of objects that depend on the particular implementation.
These are the Javascript aspects I’ll treat in next posts:
- Objects and Functions.
- Inheritance.
- Scope chain.
- Arrays.
And for each of then, I’ll try to give a Javascript framework example where it is clearly used the concept we’re treating in that moment. Ok, so let’s start with the first Javascript feature I’d like to face:
Execution Context
Definition:
When control is transferred to ECMAScript executable code, control is entering an execution context. Active execution contexts logically form a stack. The top execution context on this logical stack is the running execution context. A new execution context is created whenever control is transferred from the executable code associated with the currently running execution context to executable code that is not associated with that execution context. The newly created execution context is pushed onto the stack and becomes the running execution context.
Basically, the evaluation of a certain type of code creates an execution context which is set on the top of the “execution contexts stack”. On the other hand, there are 3 kind of executable code:
- Global code (Code defined in the main program block, so outside of any function(){} block).
- Eval code (Code executed by eval()).
- Function code (Code inside a function(){} block).
And each of them have their own features. In general, let’s say that each context created has associated a Variable Object where is kept some of the needed data for the specific context and related code to run. In the case of Function code, its Variable Object associated to the context created when the control is transferred to it, is called Activation Object. For Global Code the Variable Object is the same Global Object (in browsers – window).
That’s all about Execution Contexts?
Of course not, since an execution context has a Variable Object plus a Scope chain (there has to be a way to access variables defined in parent methods) and a Context Object (our well known friend this).
Which info holds the Variable Object?
In context associated to global code:
- variables
- function declarations
In context associated to function code (Activation Object):
- variables
- function declarations
- formal parameters
- arguments object (which is a map of formal parameters but with index-properties)
What is the Scope chain? And Eval code? …
This is just the main structure of the article, I’m preparing the examples, extended explanations and frameworks code (…)
0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment