mozilla

Compare Revisions

Object.prototype.constructor

Change Revisions

Revision 87956:

Revision 87956 by Andrea@3site.it on

Revision 87957:

Revision 87957 by Andrea@3site.it on

Title:
constructor
constructor
Slug:
JavaScript/Reference/Global_Objects/Object/constructor
JavaScript/Reference/Global_Objects/Object/constructor
Content:

Revision 87956
Revision 87957
tt81</pre>
82    <h4 name="Example:_Changing_the_constructor_of_an_object">
83      Example: Changing the constructor of an object
84    </h4>
85    <p>
86      The following example shows how to modify constructor value
 > of generic objects. Only true, 1 and "test" variables will not b
 >e changed. This example explains that is not always so safe to be
 >lieve in constructor function.
87    </p>
88    <pre>
89function Type(){};
90var     types = [
91        new Array,      [],
92        new Boolean,    true,
93        new Date,
94        new Error,
95        new Function,   function(){},
96        Math,   
97        new Number,     1,
98        new Object,     {},
99        new RegExp,     /(?:)/,
100        new String,     "test"
101];
102for(var i = 0; i &lt; types.length; i++){
103        types[i].constructor = Type;
104        types[i] = [types[i].constructor, types[i] instanceof Typ
 >e, types[i].toString()];
105};
106alert(types.join("\n"));

Back to History