overriding Function object Prototype property value differs in case the internal property of an instance object prototype value

Source: Internet
Author: User

http//www.cnblogs.com/cmptlgg/my Blog Parkoverriding the Prototype property value of a function object: the connection of the [[Prototype]] internal properties of the instance and the Prototype (prototype object) of the original function object is severed, this example refers to JS Advanced Third Edition;/*This is the interpretation of this implementation by the senior Senior. Although you can add properties and methods to your prototype at any time, and the modifications are immediately reflected in all object instances, the situation is different if you rewrite the entire prototype object. We know that when the constructor is called, a [[Prototype]] Pointer to the original prototype is added to the instance, and modifying the prototype to another object is tantamount to cutting off the connection between the constructor and the original prototype. Keep in mind that the pointer in the instance points only to the prototype, not to the constructor. Look at the following example. */Let's look at how the ECMA standard implements these operations; The individual is simply saying, not entirely. functionPerson () {//When you create a function, you create a function object p creates some properties for the P object in the algorithm created by the function object, including the internal properties (denoted by [[]]). The internal property is initialized to P. [[Prototype]]=function.prototype;P.prototype=NewObject () produces a new object that acts as a prototype object for p;}varFriend =NewPerson ();//The new operator invokes [[Construct]] This internal method of the previous person function object to see its algorithm stepping (abbreviated); obj is the newly created ECMAScript native object. Creates an internal property for this obj object; [[Prototype]]=person.prototype; Gets the prototype property in the preceding function object.] Some of the following steps are omitted. The result that will return [[construct]] is an object. //we know that when you create a function object, the prototype property value is the initialized new object (). Person.prototype = {/*this modifies the previously created function object P.prototype, but the value of the new object's [[prototype]] is initialized to obj before modifying the p.prototype. [[Prototype]]=person.prototype. So the value of [[prototype]] for the object of new is still the previous person.prototype. You can see that this value has not been modified*/Constructor:person,name:"Nicholas", Age:29, Job:"Software Engineer", Sayname:function() {alert ( This. name);}; Friend.sayname (); //error So here's an error. There's nothing to say about how to find the properties of an object here. Not in the scope of this chapter. //here we put var friend = new person (), and it's not the same when you put the change to the prototype property. The reason for this is because there is no modification to the [[Prototype]] property of the new object. If it is modified. Point to the modified value. functionPerson () {}person.prototype={The prototype property value of the function object is changed to a new object directly here; Constructor:person,name:"Nicholas", Age:29, Job:"Software Engineer", Sayname:function() {alert ( This. name);};varFriend =NewPerson ();//The result here will return [[Construct]] is an object. In the behavior of this internal method it is evident that the new object of the [[Prototype]]=person.prototype; Prototype value of the previously created function object has been modified. The value here is a pointer to an object called the prototype object. friend.sayname (); Eject"Nicholas";//Finally, in the final analysis, it is a sequential relationship of the execution process, in a different order. The results will also be different. What's wrong with this article, please comment, thank youWeb Technology+winapp Technology Learning Exchange Group 162791594

overriding Function object Prototype property value differs in case the internal property of an instance object prototype value

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.