node-buffalo icon indicating copy to clipboard operation
node-buffalo copied to clipboard

writeElement can't process the Number or String object

Open flier opened this issue 14 years ago • 2 comments

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

flier avatar Jan 14 '12 05:01 flier

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.

marcello3d avatar Jan 18 '12 03:01 marcello3d

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

flier avatar Jan 28 '12 02:01 flier