We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如果我们想要对一个数据按照对象进行操作,那么我们有必要先将其对象化。 对一个数据进行对象化,据我所知有两种方法:
var myObj = obj || {}
var myObj = Object(obj)
underscore中大量地使用了第二种方法 那么,这两种方式有什么区别呢,我们来分别看一下:
这段代码的意思是:
undefined, null, 0, NaN, false, ""
{}
var obj = Object(2); // 相当于 new Number(2); 返回的是一个对象 // => Number {[[PrimitiveValue]]: 2} var obj = Object(NaN); // 相当于 new Number(NaN); 返回的是一个对象 // => Number {[[PrimitiveValue]]: NaN} var obj = Object(""); // 相当于 new String(""); 返回的是一个对象 // => String {length: 0, [[PrimitiveValue]]: ""}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
如果我们想要对一个数据按照对象进行操作,那么我们有必要先将其对象化。
对一个数据进行对象化,据我所知有两种方法:
var myObj = obj || {}
var myObj = Object(obj)
underscore中大量地使用了第二种方法
那么,这两种方式有什么区别呢,我们来分别看一下:
1.
var myObj = obj || {}
这段代码的意思是:
undefined, null, 0, NaN, false, ""
这类能转成 false 布尔值的数据时,那么就将{}
赋值给 myObj2.
var myObj = Object(obj)
这段代码的意思是:
{}
The text was updated successfully, but these errors were encountered: