Hacker News new | past | comments | ask | show | jobs | submit login

Everyday you learn something new

  Number.prototype.times=function(fn){
    for(i=0;i<this;i++){ fn(i); }
  }

  3..times(alert)



If somebody’s wondering about the double dot like me: “A common misconception is that number literals cannot be used as objects. That is because a flaw in JavaScript’s parser tries to parse the dot notation on a number as a floating point literal.”


But then, "native prototypes should never be extended unless it is for the sake of compatibility with newer JavaScript features."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: