1. Definitions

Method

a function associated with an object with a property.

Object

An object is an unordered collection of properties each with zero or more attributes that determine how each property can be used. See more

Reference

Reference type is not a language data type. It is used for expository purposes. A Reference is a reference to a property of an object which has two parts - base object and property name.

[[PropertyName]]

This denotes an internal property which can be not accessed by javascript code.

[[Prototype]]

This internal property is kind of special. The prototype chain is constructed based on value of this property.

prototype (property)

This property is also special. Value of property [[Prototype]] of child objects is set to value of this property.

Function

It is a native object.

Function objects

These objects child objects of Function. They are created using [function definition syntax or expression new Function(…).

Instances of Function objects

They are child objects of Function objects.

function func(){   //A Function object would be created
    alert("hello,world");
}
var a = new func(); //An instance of function object - func is created

2. Source Text

Source text is represented as a sequence of character in the Unicode encoding, using the UTF-16 format. Non-Latin Unicode characters are allowed in identifiers, string literals, regular expression literals and comments. In string literals, regular expression literals and identifiers, any character can be expressed as a Unicode escape sequence in the format \uxxxx (\u followed by four hexadecimal digits). It contributes one character to the value. Format control characters are moved from source text before applying the lexical grammar. One must use a escape sequence to include a format-control character in a string or regular expression literals.

3. Types

In Javascript, there are two kinds of types - primitive types and Object.

3.1. Primitive types

Undefined

This type has exactly one value, called undefined. undefined represents that variable has not been assigned a value.

Null

This type has exactly one value, called null. null represents the null, empty or non-existent reference.

Boolean

Represents logical entity. It consists of two values - true and false.

Number

A set of number values. Each number value directly represents a number - double-precision 64-bit format IEEE 754 (including NaN, positive infinity and negative infinite). Positive infinity is produced by expression +Infinity and negative infinity is produced by expression -infinity.

String

set of all string values. A string value is a finite ordered sequence of zero or more 16-bit unsigned integer values.

3.2. Objects

An object is an unordered collection of properties each with zero or more attributes that determine how each property can be used. Properties are containers that hold (1) other objects, (2) primitive values, or (3) methods. Every property can have zero or more attributes from the list: ReadOnly, DontEnum, DontDelete, and Internal.

Object type

function(object that has property [[Call]]): they can be invoked with arguments.
constructor(object that has property [[Construct]]): intended for use with new operator.

Constructor
  • What?

    A constructor is a Function object that creates and initializes objects. All constructors are objects, but not all objects are constructors. Each constructor has a Prototype property that can be used to implement property-based inheritance and shared properties.
    We can assume constructor has an internal property [[Construct]].

  • How to use?

    Objects are created by using constructors in new expressions. Invoking a constructor without using new has consequences that depend on the constructor.

  • Inheritance

    Every constructor has an associated property - prototype, and every object created by that constructor has an implicit reference to the prototype. It can be accessed using <constructor>.prototype. A prototype may have a non-null implicit reference its prototype. This is called prototype chain. So properties owned by an object’s prototype are shared by all objects sharing the prototype.
    Note: there is no implicit prototype link between constructor and its prototype. The link is explicit. In prototype chain, all prototype links are implicit.

  • Property lookup

    When a reference is made to a prototype in an object, the first object in the prototype chain that contains a property of that name wins.

  • vs. class-based object-oriented language

    The state and methods are carried by objects and structure, behavior, and state are all inherited.

4. Function definition

4.1. Syntax

4.2. Function object creation

Note: This is also done when expression var f=new func(parameters) is evaluated.

4.3. Property [[Construct]] of Function objects/instances

This is called when the user creates an object using expression new FunctionObject().

Note: because prototype chain is set up before execution of function code, those properties of objects comprising the prototype chain can be used in function body.

4.4. Property [[Call]] of Function objects/instances

If the [[Call]] property is not empty, the Function object can be called as a function. Execution steps include

5. Execution

5.1. Execution Context

Every execution context has a scope chain.

5.2. Entering an execution context

Every function and constructor call enters a new execution context. Every return exits an execution context. When control enters an execution context,

Detailed steps depend on type of the code.

type of code scope chain variable instantiation this

Global code

contains the global object and no others

uses global object as the variable object and uses property attributes DontDelete.

the global object

Eval code

contains the same objects as the calling context’s scope chain. If null, uses global object.

uses the calling context’s variable object and uses empty property attributes.

the same as the this value of the calling context

Function code(does not include body of nested function declarations)

contain the activation object followed by the objects in the scope chain stored in the Scope property of the Function object

uses activation object as the variable object and uses property attributes DontDelete.

The caller provides the this value. If it is not an object(including the case it’s null), this value is the global object

5.3. Function execution context

Two objects are automatically created when entering function execution context.

6. Native object

Usually, unless specified, type of a built-in object is "Function" if that object has a [[Call]] property or "Object" otherwise.

But most of the built-in functions don’t have a prototype property.

Relationship among native objects and object prototypes

Javascript objects

Some native objects and their properties
Object [[Construct]] [[Call]] [[Prototype]] [[Class]] prototype

Global

None

None

implementation dependent

implementation dependent

None?

Object

create an object

perform type conversion

Function prototype

"Object"

Object prototype

Object prototype

Null

Null

Null

"Object"

Null

Function

initializes a new Function object[1]

creates and initializes a new Function object

Function prototype

"Function"

Function prototype
(DontEnum, DontDelete, ReadOnly)

Function prototype

Seems not Null. No specification was found in E262-3.

[2]

Object prototype

"Function"[2]

Null

Function objects[3]

see here

see here

Function prototype

"Function"

new Object()

Array

Initializes the newly created object

Creates and initializes a new Array object.[4]

Function prototype

"Function"

Array prototype

Array prototype

Null

Null

Object prototype

"Array"

String

intializes the newly created object

performs a type conversion

Function prototype

"Function"

String prototype

String prototype

Null

Null

Object prototype

"String"

[1] Function(…) is equivalent to expression new Function(…).

[2] Function.prototype is a Function object itself. When invoked, it accepts any arguments and returns undefined.

[3] They are child objects of object Function. So each object represents a declared function. Each object can be used to construct child objects using expression new FunctionName(…) or called as a function.

[4] Array(…) is equivalent to expression new Array(…).

External(public) properties of native objects

Javascript 1.5 Reference on Mozilla

7. Misc

typeof

Return value of applying typeof operator is different from value of property .

property access

object.property is equivalent to object[property-string] For example, object[name] is equivalent to object["name"].

Object creation using new

var variable = new ObjName(parameters);

  1. Get the object referenced by ObjName called O

  2. Call the [[Construct]] method on O

Function call

var returnValue = functionRef(parameters);

  1. Get the object referenced by functionRef called F

  2. Get value of this

    • If functionRef is a Reference, get the base object called B

      • if B is an activation object, set this to null

      • else set this to B

    • else set this to null

  3. Call the [[Call]] method on F with this and passed-in parameters. See more

  4. Return result of step 3)

Array initialization

Any elements may be elided anywhere in the array initializer.

var = new Array[1,2,,4];

length of the array is 4 instead of 3. The third element is undefined.

Object initializer
var obj = {}
var obj2 = {name: "myname"}

Values are evaluated each time the object initializer is evaluated.

Operator typeof

See https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/typeof_Operator. Note: the result of applying typeof operator to Null type is object!! In other words, typeof null returns string object.

Equal and Strict Equal

8. Resources

Emca Script
JS resources hosted on Mozilla
Javascript 1.5 Reference on Mozilla