Skip to main content

Posts

Showing posts with the label structure

Javascript function and object structure

Javascript has function and object structure. We tries to understand this. Function is an object and an object is created by some function. When a function creates an object, the function assign its prototype value to __proto__ property of newly created object. Object.prototype  is the last object in prototype chain. It is base object for all functions and objects. Javascript has pattern that __proto__ of function would be type of function and __proto__ of object would be type of object. This is also true for Number, Array etc. Lets check diagram of javascript function and object structure. (We shall call in-built unnamed function as System function .) If we create obj using object literal, var obj = { a: 0 }; The obj is created by Object . Here, the Object function is used implicitly as creator function. obj.__proto__ === Object.prototype   // true If we create an instance using creator function. var foo = new Foo(); ...