开发者

JavaScript prototype of function not working properly

开发者 https://www.devze.com 2023-03-09 06:43 出处:网络
I`ve made a prototype for \"between\" function. Why I 开发者_如何学编程can\'t use it directly on number? It is Number object whatsoever!

I`ve made a prototype for "between" function. Why I 开发者_如何学编程can't use it directly on number? It is Number object whatsoever!

var a = 21;
21.between("( 16 20 ]"); // this is wrong and not working
//alert ( typeof 21 ) is number
a.between("( 16 20 ]");  // working


Try:

(21).between("( 16 20 ]");

When the parser (well, the lexer) sees "21." it thinks you've got a floating-point constant. What also works (and what really looks icky to me personally) is:

21..between("( 16 20 ]");
0

精彩评论

暂无评论...
验证码 换一张
取 消