To undertake the previous article,
Objectkeys
The Keys method of object can get all the keys of a given object (the Key/property name) and return it as an array. This method can be used for key filtering, matching, and so on.
varBasket = {Strawberry: A, Banana: -, Apple: -, Juice: -};Console. log (Object. Keys (basket));//[' strawberry ', ' banana ', ' apple ', ' juice ']
Create
The Create method is used for creating a new object, an optional parameter (proto, [Propertiesobject]), the first being a prototype, such as Array.prototype, and the second for some new properties that need to be created for the new object, The property name of this parameter object is the property of the new object, and the value is the property descriptor (value, writable, configurable, and so on).
varn \Object. Create ({}, {p: {value: the}});varO =Object. Create ({}, {p: {value: the, writable:true, Enumerable:true}});Console. log (O.P);//42Console. log (O.P);//66O.P = -; O.P = the;Console. log (O.P);//42Console. log (O.P);//80
Property descriptor writable defaults to False, Therefore O.P even in the subsequent re-assignment can not change its value, and O.P can change the value later, in addition, the Create method proto must pass the corresponding parameters, otherwise the error typeerror, of course, the above code in strict mode will also error, because O.P is rewritten--
Assign
The Assign method, a new feature of the ES6, supports the target object, which is used to add the key-value pairs of any number of source objects, similar to the assign and underscore methods of Lodash Extendown, for the reference (target, ... sources).
varBoy = {handsome:true, Rich:true}, girl = {cute:true, Hair:' Long '};varCouples =Object. Assign ({}, Boy, girl);Console. log (couples);//{handsome:true, rich:true, cute:true, Hair: ' Long '}
The Assign method is often used for frame-level data processing, such as when you define a client to send an HTTP request, and use it to get the default attributes that might be added to the received parameters.
Numberisnan
The isNaN method of number is used to determine whether the passed value is a value of NaN, and unlike the global isNaN method, it does not force an incoming parameter to be converted to a number type, and returns true only if the argument is a true numeric type and the value is Nan. But as far as I'm concerned, the global isNaN use a bit more to determine whether a string contains only numbers,
Console. log (IsNaN(' 123f '));//trueConsole. log (IsNaN(' 123 '));//true
In addition, the Isfinite (value) method is used to determine whether an incoming parameter is a poor number, and the Isinteger (value) method is used to determine whether an incoming parameter is an integer.
ToFixed
The Tofixed method is used to convert a number to a specific string, supports incoming parameters (digits), 0 < digits <= 20, and is automatically rounded and 0 replenished when converted.
varCool =666.666;Console. log (Cool.tofixed (1));//666.7Console. log (Cool.tofixed (6));//666.666000
A lot of things have happened in this period, from Hangzhou, which has been 116 days, to Beijing to start a new work and life. Do not shed, melancholy, excitement, excitement and other emotional intertwined lingering ... Seven wolves, know the rest of the six wolves, very cherish this section of everyone together to get together hi leather days, especially remember the night climb Gem Mountain, overlooking the West Lake, Chinese poor, ha haha ...
Toward the Dream, go! baby!
To learn more, please visit my blog.
JavaScript Utility Method Two