Search code examples
javascriptfunction-prototypes

JavaScript prototype of function not working properly


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

Solution

  • 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 ]");