writeElement can't process the Number or String object
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
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.
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