Skip to content
New issue

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

writeElement can't process the Number or String object #4

Open
flier opened this issue Jan 14, 2012 · 2 comments
Open

writeElement can't process the Number or String object #4

flier opened this issue Jan 14, 2012 · 2 comments

Comments

@flier
Copy link

flier commented Jan 14, 2012

As you know, 3.14 and new Number(3.14) are same in Javascript, but typeof(3.14) == 'number' and typeof(new Number(3.14)) == 'object', the writeElement function in bson.js doesn't process the second situation, including Number, String and Boolean.

http://bonsaiden.github.com/JavaScript-Garden/zh/#types.typeof

@marcello3d
Copy link
Owner

Does this happen often?

Do you know of a reliable performant way of checking for these types? I'm worried that foo instanceof Number is insufficient When there are different contexts, the Number class in buffalo could be a different instance than the module that created the Number.

@flier
Copy link
Author

flier commented Jan 28, 2012

After read some articles, I choose to use the class name :)

var getClassName = function (obj) {
var name = Object.prototype.toString.call(obj).slice(1, -1);

return name.substr(name.indexOf(' ')+1);

};

https://github.com/flier/vine/blob/master/src/utils/bson.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants