jcompagner wrote:yes i think that typeof is just strange...
dont know why you would really us that
typeof is necessary to discover datatypes.
instanceof seems to be way more specific gives you way more output the for many things then just 'object'
instanceof won't work on primitives at all (and does not discover datatypes). Its syntax requires a Class' constructor name as the right hand operand and there is no constructor for the primitives. The proof to this is below...
- Code: Select all
false instanceof boolean
will throw an exception (unsupported operand really)!
So instanceof is there to tell you if a particular object is an instance of a particular class, and that isn't synonymous with datatype in JS.
js does know Date as a object type and everything is just Object
It knows Date as an object yes, but not as a datatype. there is no Date/date datatype in JS.
thats why when you create:
var x = true
and you give that to a function
you can use.
@param {Boolean}
@param {boolean}
@param {Object}
@param {object}
all 4 are fine to use
Actually in that particular example true is primitive and is not Boolean, nor is it Object, nor even object. It is only primitive / boolean. So the docblock would only be accurate if it ready @param {boolean}
I mentioned before that I wasn't really suggesting that anything was wrong with the Servoy implementation, but I think I am changing my mind b/c now that I see that somehow there are parameters being passed around that are somehow both (for example) Boolean and boolean, I believe that something is arye. Perhaps there is some inproper casting happening somewhere or an accessor has been overwritten? I don't know how something can be both boolean and Boolean. Meaning it shouldn't be possible for something to be an instance of Boolean and be primitive.
REMINDER: I'm only brining this up b/c of the following reported fix.
[fix] 360543 DLTK: no warning generated for functions that don't return what the JSDoc specifies or vise versa
And I am thinking that if the editor is going to warn me about an improper return value, which does not match @returns it would be most useful if it caught differences between primitives and objects. Otherwise I suppose it is really only catching returning a string when you show @returns {Boolean} etc, and while that is really helpful, it's easier to spot that on your own, whereas sometimes it's harder to spot the other cases.