object.assign(value)
The value to be assigned. The assign() method should, in some fashion, assign value to the object.
Nothing.
The assign() method is not one you usually call explicitly in your JavaScript code. Instead you define this method for certain objects, and the system invokes the method automatically when a value is assigned to that object.
If an object o has an assign() method defined, then the assignment:
o =index.html value;
o.assign(value);
The assign() method should be written to expect a single argument, which will always be the value of the right-hand side of an assignment operator. When invoked, the object will refer to the left-hand side of the assignment. The body of the method should "assign," in some appropriate fashion, the value to the object.
You might define the assign() method when you want assignment to an object to perform some sort of side effect. For example, in client-side JavaScript, assigning a URL value to the location field of a window object causes the browser to load that URL into the window.
Sometimes, you may want to define an assign() method for only one single special object. In other cases, however, you will want all instances of a class of objects to have a special assignment behavior. In this case, you should set the assign() method in a constructor function or a prototype object.
The following code shows how you could define an assign() method for a class of objects so that when one object of this class is assigned to another, the object's fields will be assigned "by value," rather than assigning "by reference."
// Define a function suitable for use as our assign() method. function copy_fields(value) { for (field in value) this[field] =index.html value[field]; } // Define it as the assign() method in a prototype object, so that // all instances of the object type have this assign() method. MyObject.prototype.assign =index.html copy_fields;
file: /Techref/language/JAVA/SCRIPT/definitive/refp_275.htm, 6KB, , updated: 2019/10/14 15:00, local time: 2024/12/24 08:03,
3.14.245.172:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.ecomorder.com/Techref/language/JAVA/SCRIPT/definitive/refp_275.htm"> [Chapter 21] Reference: Object.assign()</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.