Using JavaScript's built-in objects
Briefly

Object is the root object of all prototypes in JavaScript. Aside from providing the foundation for the JavaScript object model, Object imparts important methods such as toString() and assign(). Every object in JavaScript has these methods thanks to Object.
The toString() method is very simple. You can call it on anything, and if nothing has been defined, it'll use the default version. Many objects, like arrays, do define their own version. Custom objects can also define a version. When you interpolate an object into a string literal- console.log("This is my object: " + myObject)-it will call the toString() method.
The assign() method is a mechanism for cloning objects. It is a static method on Object itself: let object1 = {foo:"bar"}; let object2 = Object.assign({}, object1); console.log(object2.foo); // outputs "bar" Note that assign() makes a shallow copy, meaning it doesn't copy nested properties. Also, the copy has references to the same pointer properties (that is, object1.objectRef === object2.objectRef).
Of all of JavaScript's built-in objects, JSON may be the most commonly used. It lets you transform between string JSON and live JSON objects. (For more about JavaScript Object Notation, see InfoWorld's primer, What is JSON?). The JSON object is useful all the time. Here's an example that might be familiar:
let stringJson = '{"nums": [1,2,3,4]}'; console.log(JSON.parse(stringJson).nums[0]); // outputs "1" let jsonObject = {"letters": [a,b,c,d]}; console.log(JSON.stringify(jsonObject)); // outputs "{"letters": [a,b,c,d]}"
Read at InfoWorld
[
add
]
[
|
|
]