The above example sets the default value (0,0) for the Point object through prototype, so the value of p1 is (0,0) and the value of p2 is (1,2). Through delete , delete ; The value of p2 can be restored to (0,0). Here is a more interesting example:
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
Using prototype can also set a read-only getter for the object's properties to avoid it being overridden. Here is an example:
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
Rewrite() to the following:
= function()
{
function GETTER(){};
= m_firstPoint;
return new GETTER();
}
This problem can be avoided and the read-only nature of the m_firstPoint attribute is ensured.
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
In fact, setting an object as a type prototype is equivalent to instantiating this type and establishing a read replica for the object. Changing the replica at any time will not affect the original object. Changes to the original object will affect the replica unless the changed attribute has been overwritten by the replica's own attribute of the same name. Use the delete operation to delete the object's own attribute of the same name to restore the visibility of the prototype attribute. Here is another example:
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
Previous page123Next pageRead the full text