Discover object prototype hasownproperty call, include the articles, news, trends, analysis and practical advice about object prototype hasownproperty call on alibabacloud.com
__. constructor, obj. hasownproperty ('constructor'); false
Function Y (){ This . Y = 99 ;} VaR OBJ =New Y (); console. Log (obj. constructor ); // Y Console. Log (obj. hasownproperty ( 'Constructor ')); // False Console. Log (obj. _ PROTO _. hasownproperty ( 'Constructor ')); // True // ===== Function X (){ This . X = 88 ;} Function Y (){ This
Object. prototype. toString. call () method, object. tostring. call
Use the native toString () method on Object. prototype to determine the data type. Use the following method:Object.
‘):undefined;dict.hasOwnProperty(‘x‘)?dict.hasOwnProperty(‘x‘):undefined;Here is another problem, we are using the Dict object hasOwnProperty method, but in fact, it does not have this method, but it inherits from the Object.prototype object. If the Dict Dictionary object has a property of the same name as "
:
// Object (a instanceof Object )! (A instanceof Function )! (A instanceof Function) // Array (a instanceof Object) (a instanceof Array) // Function (a instanceof Object) (a instanceof Function)
The simpler way is to use Object. proto
hasOwnProperty: is used to determine whether an object has a property or object that you give a name to, and this method cannot check whether the object has that property in its prototype chain, and that property must be a member of the
constructed object is executed in the apply () method. The purpose of apply () is described later, and initialize is continued. In this way, the initialize will be contacted when the object is initialized (the application is required for how to contact the object ).SoCopy codeThe Code is as follows: A. Prototype = {In
apply () method. The purpose of apply () is described later, and initialize is continued. In this way, the initialize will be contacted when the object is initialized (the application is required for how to contact the object ).SoCopy codeThe Code is as follows:A. prototype = {Initialize: function (v ){This. value = v;}ShowValue: function (){Alert (this. value )
The publisher statement in publish/subscribe mode converts arguments to an array.
VaR ARGs = array. Prototype. Slice. Call (arguments, 0 );
This kind of built-in object prototype call can be used;
The "internal object
said to continue to say initialize. This will contact the initialize when initializing the object (how to contact is to see apply). Then copy the code code as follows: a.prototype={initialize:function (v) {this. value=v;} showvalue:function () {alert (this.value);}} what does it mean?? Prototype is the meaning of "archetype". A is a function (), then A. Prototype
.
var foo = { hasOwnProperty: function() { return false; }, bar: 'Here be dragons'};foo.hasOwnProperty('bar'); // always returns false// Use another Object's hasOwnProperty and call it with 'this' set to foo({}).hasOwnProperty.call(foo, 'bar'); // true// It's also possible to use hasOwnProperty from the
First, the cause
That day to Prototype.js opened to see, only to see a few lines on the full head fog, the reason is not very familiar with the object-oriented JS, so Baidu +google a handful, finally count small have harvest, write this commemorative ^_^.
Prototype.js Code Fragment
Copy Code code as follows:
var Class = {
Create:function () {
return function () {
This.initialize.apply (this, arguments);
}
}
}
Class uses t
Tips for using criptisprototypeof and hasOwnProperty. If you need a friend, refer.
1. isPrototypeOf
IsPrototypeOf is used to determine whether the specified object object1 exists in the prototype chain of another object object2. If yes, true is returned; otherwise, false is returned.
The format is as follows:
Object1.
the attribute, which must be a member of the object itself.
Returns true if the property or method is defined by the object itself, rather than defined in the prototype chain;
The format is as follows:
Object.hasownproperty (Proname);
Determines whether the name of the Proname is a property or object of the
Tag:gesdivimg name console prototype ons.compush var obj = {name: " echolun " " 24 " , sex: " Span style= "COLOR: #800000" >male " }, objname =[], // used to load object property name objval=[]; // for (var i in obj) {objname.push (i); Objval.push (Obj[i]);} Console.log (objname,objval); It is important to note that the for In loop object
(person2.name);//"Nicholas"--from the prototype
delete person1.name;
alert (person1.name); "Nicholas"--from prototypes
In this modified example, we removed the person1.name using the delete operator, which previously saved the "Greg" value masking the stereotype attribute with the same name. After it is deleted, the connection to the Name property in the prototype is restored. Therefore, the next time you
constructor.III. Basic Methods[1] isPrototypeOf (): determines whether the Instance Object and prototype object exist in the same prototype chain, as long as it is a prototype that has appeared in the prototype chain, it can be s
= new Box (); console. log (box2.name); // Lee; Value in the prototype; not modified by box1; // if you want box1 to continue accessing the value in the prototype, you can delete the attributes in the constructor. delete box1.name; // delete the attributes of the instance. console. log (box1.name); // Lee; Original Value in the prototype;
2.
obj2 = Object. create (proto ,{Foo: {value: 'obj2 '}});In this way, the created obj2 has all the ProtoClass member attributes a, B, c, and aMethod prototype methods, and adds a foo read-only data attribute;Copy codeThe Code is as follows:Obj2.a; // ProtoClassObj2.c: // [Object]Obj2. B ();//
Obj2.aMethod (); // ProtoClassObj2.foo; // obj2
3. Subclass inheritance:
.hasownproperty (' age '));//true -Console.log (Obj2.age);//---> From prototype objects -Console.log (Obj2.hasownproperty (' age '));//false the DeleteObj1.age; -Console.log (Obj1.age);//---> From prototypes -Console.log (Obj1.hasownproperty (' age '));//falseVI, in operatorDetermines whether the property is on
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.