X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6746dc89c47ed01b165cc1152533605f97eb8e8d..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/docs/output/Object.js diff --git a/docs/output/Object.js b/docs/output/Object.js new file mode 100644 index 00000000..84edc8f1 --- /dev/null +++ b/docs/output/Object.js @@ -0,0 +1 @@ +Ext.data.JsonP.Object({"tagname":"class","html":"
Files
Creates an object wrapper.
\n\nThe Object constructor creates an object wrapper for the given value. If the value is null or\nundefined, it will create and return an empty object, otherwise, it will return an object of a type\nthat corresponds to the given value.
\n\nWhen called in a non-constructor context, Object behaves identically.
\n\nThe following examples store an empty Object object in o:
\n\nvar o = new Object();\n\nvar o = new Object(undefined);\n\nvar o = new Object(null);\n
\n\nThe following examples store Boolean objects in o:
\n\n// equivalent to o = new Boolean(true);\nvar o = new Object(true);\n\n// equivalent to o = new Boolean(false);\nvar o = new Object(Boolean());\n
\n\nSpecifies the function that creates an object's prototype.
\n\nReturns a reference to the Object function that created the instance's prototype. Note that the\nvalue of this property is a reference to the function itself, not a string containing the\nfunction's name, but it isn't read only (except for primitive Boolean, Number or String values: 1,\ntrue, \"read-only\").
\n\nAll objects inherit a constructor
property from their prototype
:
o = new Object // or o = {} in JavaScript 1.2\no.constructor == Object\na = new Array // or a = [] in JavaScript 1.2\na.constructor == Array\nn = new Number(3)\nn.constructor == Number\n
\n\nEven though you cannot construct most HTML objects, you can do comparisons. For example,
\n\ndocument.constructor == Document\ndocument.form3.constructor == Form\n
\n\nThe following example creates a prototype, Tree
, and an object of that type, theTree. The example then displays the constructor
property for the object theTree
.
function Tree(name) {\n this.name = name;\n}\ntheTree = new Tree(\"Redwood\");\nconsole.log(\"theTree.constructor is \" + theTree.constructor);\n
\n\nThis example displays the following output:
\n\ntheTree.constructor is function Tree(name) {\n this.name = name;\n}\n
\n\nThe following example shows how to modify constructor value of generic objects. Only true, 1 and\n\"test\" variable constructors will not be changed. This example explains that is not always so safe\nto believe in constructor function.
\n\nfunction Type(){};\nvar types = [\n new Array, [],\nnew Boolean, true,\nnew Date,\nnew Error,\nnew Function, function(){},\nMath,\nnew Number, 1,\nnew Object, {},\nnew RegExp, /(?:)/,\nnew String, \"test\"\n];\nfor(var i = 0; i < types.length; i++){\n types[i].constructor = Type;\n types[i] = [types[i].constructor, types[i] instanceof Type, types[i].toString()];\n};\nalert(types.join(\"\\n\"));\n
\nReturns a boolean indicating whether an object contains the specified property as a direct property\nof that object and not inherited through the prototype chain.
\n\nEvery object descended from Object
inherits the hasOwnProperty
method. This method can be used\nto determine whether an object has the specified property as a direct property of that object;\nunlike the in
operator, this method does not check down the object's prototype chain.
The following example determines whether the o object contains a property named prop:
\n\no = new Object();\no.prop = 'exists';\n\nfunction changeO() {\n o.newprop = o.prop;\n delete o.prop;\n}\n\no.hasOwnProperty('prop'); //returns true\nchangeO();\no.hasOwnProperty('prop'); //returns false\n
\n\nThe following example differentiates between direct properties and properties inherited through the\nprototype chain:
\n\no = new Object();\no.prop = 'exists';\no.hasOwnProperty('prop'); // returns true\no.hasOwnProperty('toString'); // returns false\no.hasOwnProperty('hasOwnProperty'); // returns false\n
\n\nThe following example shows how to iterate over the properties of an object without executing on\ninherit properties.
\n\nvar buz = {\n fog: 'stack'\n};\n\nfor (var name in buz) {\n if (buz.hasOwnProperty(name)) {\n alert(\"this is fog (\" + name + \") for sure. Value: \" + buz[name]);\n }\n else {\n alert(name); // toString or something else\n }\n}\n
\nThe name of the property to test.
\nReturns true if object contains specified property; else\nreturns false.
\nReturns a boolean indication whether the specified object is in the prototype chain of the object\nthis method is called upon.
\n\nisPrototypeOf
allows you to check whether or not an object exists within another object's\nprototype chain.
For example, consider the following prototype chain:
\n\nfunction Fee() {\n // . . .\n}\n\nfunction Fi() {\n // . . .\n}\nFi.prototype = new Fee();\n\nfunction Fo() {\n // . . .\n}\nFo.prototype = new Fi();\n\nfunction Fum() {\n // . . .\n}\nFum.prototype = new Fo();\n
\n\nLater on down the road, if you instantiate Fum
and need to check if Fi
's prototype exists\nwithin the Fum
prototype chain, you could do this:
var fum = new Fum();\n. . .\n\nif (Fi.prototype.isPrototypeOf(fum)) {\n// do something safe\n}\n
\n\nThis, along with the instanceof
operator particularly comes in handy if you have code that can\nonly function when dealing with objects descended from a specific prototype chain, e.g., to\nguarantee that certain methods or properties will be present on that object.
an object to be tested against each link in the prototype chain of the\nobject argument
\nthe object whose prototype chain will be searched
\nReturns true if object is a prototype and false if not.
\nReturns a boolean indicating if the internal ECMAScript DontEnum attribute is set.
\n\nEvery object has a propertyIsEnumerable
method. This method can determine whether the specified\nproperty in an object can be enumerated by a for...in
loop, with the exception of properties\ninherited through the prototype chain. If the object does not have the specified property, this\nmethod returns false.
The following example shows the use of propertyIsEnumerable
on objects and arrays:
var o = {};\nvar a = [];\no.prop = 'is enumerable';\na[0] = 'is enumerable';\n\no.propertyIsEnumerable('prop'); // returns true\na.propertyIsEnumerable(0); // returns true\n
\n\nThe following example demonstrates the enumerability of user-defined versus built-in properties:
\n\nvar a = ['is enumerable'];\n\na.propertyIsEnumerable(0); // returns true\na.propertyIsEnumerable('length'); // returns false\n\nMath.propertyIsEnumerable('random'); // returns false\nthis.propertyIsEnumerable('Math'); // returns false\n
\n\nDirect versus inherited properties
\n\nvar a = [];\na.propertyIsEnumerable('constructor'); // returns false\n\nfunction firstConstructor()\n{\n this.property = 'is not enumerable';\n}\nfirstConstructor.prototype.firstMethod = function () {};\n\nfunction secondConstructor()\n{\n this.method = function method() { return 'is enumerable'; };\n}\n\nsecondConstructor.prototype = new firstConstructor;\nsecondConstructor.prototype.constructor = secondConstructor;\n\nvar o = new secondConstructor();\no.arbitraryProperty = 'is enumerable';\n\no.propertyIsEnumerable('arbitraryProperty'); // returns true\no.propertyIsEnumerable('method'); // returns true\no.propertyIsEnumerable('property'); // returns false\n\no.property = 'is enumerable';\n\no.propertyIsEnumerable('property'); // returns true\n\n// These return false as they are on the prototype which\n// propertyIsEnumerable does not consider (even though the last two\n// are iteratable with for-in)\no.propertyIsEnumerable('prototype'); // returns false (as of JS 1.8.1/FF3.6)\no.propertyIsEnumerable('constructor'); // returns false\no.propertyIsEnumerable('firstMethod'); // returns false\n
\nThe name of the property to test.
\nIf the object does not have the specified property, this\nmethod returns false.
\nReturns a string representing the object. This method is meant to be overridden by derived objects\nfor locale-specific purposes.
\n\nObject
's toLocaleString
returns the result of calling toString
.
This function is provided to give objects a generic toLocaleString
method, even though not all\nmay use it. Currently, only Array
, Number
, and Date
override toLocaleString
.
Object represented as a string.
\nReturns a string representation of the object.
\n\nEvery object has a toString()
method that is automatically called when the object is to be\nrepresented as a text value or when an object is referred to in a manner in which a string is\nexpected. By default, the toString()
method is inherited by every object descended from Object
.\nIf this method is not overridden in a custom object, toString()
returns \"[object type]\", where\ntype
is the object type. The following code illustrates this:
var o = new Object();\no.toString(); // returns [object Object]\n
\n\nYou can create a function to be called in place of the default toString()
method. The\ntoString()
method takes no arguments and should return a string. The toString()
method you\ncreate can be any value you want, but it will be most useful if it carries information about the\nobject.
The following code defines the Dog
object type and creates theDog
, an object of type Dog
:
function Dog(name,breed,color,sex) {\n this.name=name;\n this.breed=breed;\n this.color=color;\n this.sex=sex;\n}\n\ntheDog = new Dog(\"Gabby\",\"Lab\",\"chocolate\",\"female\");\n
\n\nIf you call the toString()
method on this custom object, it returns the default value inherited\nfrom Object
:
theDog.toString(); //returns [object Object]\n
\n\nThe following code creates and assigns dogToString()
to override the default toString()
method.\nThis function generates a string containing the name, breed, color, and sex of the object, in the\nform \"property = value;\"
.
Dog.prototype.toString = function dogToString() {\n var ret = \"Dog \" + this.name + \" is a \" + this.sex + \" \" + this.color + \" \" + this.breed;\n return ret;\n}\n
\n\nWith the preceding code in place, any time theDog is used in a string context, JavaScript\nautomatically calls the dogToString()
function, which returns the following string:
Dog Gabby is a female chocolate Lab\n
\n\ntoString()
can be used with every object and allows you to get its class. To use the\nObject.prototype.toString()
with every object, you need to call Function.prototype.call()
or\nFunction.prototype.apply()
on it, passing the object you want to inspect as the first parameter\ncalled thisArg
.
var toString = Object.prototype.toString;\n\ntoString.call(new Date); // [object Date]\ntoString.call(new String); // [object String]\ntoString.call(Math); // [object Math]\n
\nObject represented as a string.
\nReturns the primitive value of the specified object.
\n\nJavaScript calls the valueOf
method to convert an object to a primitive value. You rarely need to\ninvoke the valueOf
method yourself; JavaScript automatically invokes it when encountering an\nobject where a primitive value is expected.
By default, the valueOf
method is inherited by every object descended from Object
. Every built-\nin core object overrides this method to return an appropriate value. If an object has no primitive\nvalue, valueOf
returns the object itself, which is displayed as:
[object Object]\n
\n\nYou can use valueOf
within your own code to convert a built-in object into a primitive value.\nWhen you create a custom object, you can override Object.valueOf
to call a custom method instead\nof the default Object
method.
You can create a function to be called in place of the default valueOf
method. Your function must\ntake no arguments.
Suppose you have an object type myNumberType
and you want to create a valueOf
method for it.\nThe following code assigns a user-defined function to the object's valueOf method:
myNumberType.prototype.valueOf = new Function(functionText)\n
\n\nWith the preceding code in place, any time an object of type myNumberType
is used in a context\nwhere it is to be represented as a primitive value, JavaScript automatically calls the function\ndefined in the preceding code.
An object's valueOf
method is usually invoked by JavaScript, but you can invoke it yourself as\nfollows:
myNumber.valueOf()\n
\n\nNote: Objects in string contexts convert via the toString
method, which is different from\nString
objects converting to string primitives using valueOf
. All objects have a string\nconversion, if only \"[object type]\"
. But many objects do not convert to number, boolean, or\nfunction.
Returns value of the object or the object itself.
\n