Escolar Documentos
Profissional Documentos
Cultura Documentos
javascript):
The global object is a regular JavaScript object that serves a very important pu
rpose: the properties of this object are the globally defined symbols that are a
vailable to a JavaScript program. When the JavaScript interpreter starts (or whe
never a web browser loads a new page), it creates a new global object and gives
it an initial set of properties that define:
Use the JavaScript keyword "this" to refer to the global object from the top-lev
el code(outside any function). {ex: var ex = this;}
In client-side JavaScript, the Window object serves as the global object which h
as a self-referential window property that can be used instead of this to refer,
but it also defines quite
a few other globals that are specific to web browsers and client-side JavaScript
. When first created, the global object defines all of JavaScripts predefined glo
bal values.
But this special object also holds program-defined globals as well. If your code
declares a global variable, that variable is a property of the global object(if
the variable is defined as var... then it can be deleted, if it is defined dire
ctly then it can be deleted as a property of the global object).
#2 OBJECTS
An object is more than a simple stringto-value map. In addition to maintaining i
ts own set of properties, a JavaScript object also inherits the properties of an
other object, known as its prototype. The methods of an object are typically inher
ited properties, and this prototypal inheritance is a key feature of JavaScript. E
ven though strings, numbers, and booleans are not objects, they behave like immu
table objects.
JavaScript objects are dynamicproperties can usually be added and deleted, or can
also be used to simulate static struct/class ...
An object can more or less be called as a set of "properties" with a name-value
pair, addition to which have "property attributes":- "Writable", "Enumerable", "
Configurable".
Objects can be created in 3 ways, lets take a look at two of them,
var x = {harry: "Potter", james: "Lily", "harry potter": "Dark Lord"(if the prop
erty name contains spaces/hyphens... use quotes)};
var y = new Object()/ new Date()/ .......;
Object Prototype: Every object has a sceond associated object that is known as its prototype and t
he main object inherits the properties from the prototype. All objects defined u
sing object literal(new Object() or {}) has the prototype "Object.prototype".
new Array() has Array.prototype and new Date() has Date.prototype.... , Object.p
rototype is the rare object that does not have a prototype(i.e., it does not inh
erit any more properties) while Date.prototype has Object.prototype as its proto
1) Create a obj called "methods"(common meths all objs should have) and another
obj called "foo" the main obj you want. Make "foo" instance creator in such a wa
y that it inherits from the "methods" object. Hence, all the objects created usi
ng "foo" will have the methods in "methods". For further info, refer Javascript:
A Defenititve Guide.
2)Create a constructor function "foo", initialize the object specific values usi
ng "this" operator. Now, make the "foo.prototype" have all the common data and f
unctionalities each object is expected to have. Hence, now any object created us
ing the new "foo" will belong to the class of "foo". For further info, refer Jav
ascript: A Defenititve Guide.