Hacker Newsnew | past | comments | ask | show | jobs | submit | more chingjun's commentslogin

Can anyone explain to me why I couldn't write

  n.forEach(console.log);

Just tested on Chrome, it gives me an error

  TypeError: Illegal invocation


When you use `console.log` that way it gets `this` set to `null`. When you call `console.log("hello")`, `this` is set to `console`. Your code would work if you set an explicit `this`.

    n.forEach(console.log.bind(console));
I don't think there's any reason for this library to exist after you understand `this` semantics but I may be missing something.

e: was, in fact, missing something. Apologies for the disparaging comment, see replies.


Additionally, this will log all the passed arguments (value, index, and array being traversed), which typically isn't what you want:

    [1, 2, 3].forEach(console.log.bind(console));
    > 1 0 [1, 2, 3]
    > 2 1 [1, 2, 3]
    > 3 2 [1, 2, 3]


Well it's not just about `this` but the arguments to pass to console rather. In this case:

    n.forEach(console.log.bind(console));
forEach is passing console all of its callback arguments, resulting in logging of keys, values, and array.

EDIT: Forgot array


Ah, I understand. It reminds me of how the `cut` function could be used in Scheme.


Convenience, I suppose; I had a few headaches when I first transitioned to Javascript and discovered the odd signatures its collection functions' callbacks are expected to have.


That's one, the other is that many of those functional methods tend to mess with functions that take more than one argument when you want to use the first one, e.g parseInt.


  n.forEach(console.log);
Works on firefox. Chrome treats console.log differently from other functions for reasons unknown.

but really, this library has no reason to exist


Chinese government once blocked the download page of the python website (python.org), when they released python version 2.6.4. It is widely believed that it's because the version number triggered that[1].

Python website has since added another download link written in Chinese on their website.

[1]: http://en.wikipedia.org/wiki/Tiananmen_Square_protests_of_19... , called 六四事件 in Chinese, literally means six-four incident since it happened on 4th of June


Hah! I didn't know that since I don't use Python, but I agree with the speculation of that blocking!


When PHP announced that they will skip PHP6, we joked that it is a smart move to avoid PHP version 6.4


That's much too hilarious


Because we now have [ag](https://github.com/ggreer/the_silver_searcher), which is similar to ack, but much faster


You should avoid the obstacles while cycling. You should also stay within the safe speed limit, especially in areas with obstacles.

Same rule applies for driving, walking, and basically everything.


Swift has named arguments, and it's called "external parameter name". Here's an example taken from Apple's documentation[1].

  func join(string s1: String, toString s2: String, withJoiner joiner: String)
      -> String {
          return s1 + joiner + s2
  }
  join(string: "hello", toString: "world", withJoiner: ", ")
  // returns "hello, world"
[1]: https://developer.apple.com/library/ios/documentation/swift/...


Yeah, a developer cannot get "design".


You're not alone.


Wow I didn't know that! I was always doing something like this

    mi = dict((v,k) for k,v in m.iteritems())


I stared at the page for 10 seconds before realising that i have to use arrows. I'd suggest adding simple instructions like "Press arrow keys to navigate".


  5.  193  ^(?!.*(.)(.)\2\1)
  11. 379  ^\*(er|[fiptv])|^([blpw]|c[hor]|do|mi|re)


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: