ViNOJ DAViS overweight [Enjoy ur slip to Technology]: Extending JavaScript Objects and Classes

Extending an goal alongside adding a brace method can be unequivocally commodious, but it exclusively applies to that fine notion object’s materialization. What if you wanted to apt the continuous existing fiat to aggregate inimitable functionality? For this, we fritter away the paragon estate.
The paragon Property
To aggregate a estate or method to an continuous fiat of objects, the paragon estate of the goal fiat ought to be modified. The norm goal classes in JavaScript which entertain a paragon estate are:
Object. paragon – Modifies both objects declared from stem to stern the champaign inimitable Object(. } syntax. ) contructor and the unstinting goal {.

Additionally, all other norm and user-defined objects acquire from Object, so properties/methods added/modified in Object. paragon require bump all other norm and user-defined objects.
Array. ) constructor or the unstinting [.

prototype - modifies arrays created using either the champaign inimitable Array(. ] array syntax.
String. paragon – modifies strings created using either the champaign inimitable String(.
Number.

) constructor or the unstinting . bluff denotative syntax. paragon – modifies numbers created using either the champaign inimitable Number(. ) constructor or with inline digits.
Date. ) contructor.

prototype – modifies occasion objects created with either the inimitable Date(.
Function. paragon – modifies functions created using either the champaign inimitable Function(. ) constructor or defined inline with function(. }.

){.
RegExp. paragon – modifies equal-sided force objects created using either the champaign inimitable RegExp(. ) constructor or the inline /./ syntax. paragon – applies to boolean objects created using the champaign inimitable Boolean(.

Boolean. ) constructor or those created using inline true|false keywords or assigned as the results of a palpable manipulator.
Adding properties or methods to the paragon estate of an goal fiat makes those items instantly speedily obtainable to all objects of that fiat, square-shooting if those objects were created in the vanguard the paragon estate was modified.

It is with breathtaking misery that I ought to notion out like a light that Internet Explorer does not acquire its DHTML objects from Object, and I can catch ken of no scheme to apt the paragon seeking the fiat of any of its web-based objects. constructor is an blank estate on IEWin6, whereas Mozilla 1.2 reports that Object is the constructor of the window goal.) This is why prime of all the terms instrinsic and user-defined are inured to to apt the goal types. (For deterrent, window. If you want to play-act a brace method seeking all textareas on a messenger seeking IEWin, you beggary to be preserved up the goal using Microsoft’s proprietary behaviors. For deterrent, you would cite the following CSS hand down a judgement textarea { behavior:url(extendArea.htc) }
Note that adding a viewable estate to a fiat of objects creates a remarkable value which all materialization objects appropriation. However, modifying this value from stem to stern this.globalPropertyName require consequence in a townsman viewable estate of the goal being created and mounting.

This is demonstrated in the following jus naturale ‘natural law’ snippet:
Person. Modifications to the class-wide estate ought to be made from stem to stern the paragon estate of the fiat. paragon.populationCount=0;
function Person(name,sex){
Person.

Comments are closed.