Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

did you ever try to debug your pretty jquery karate?

ps. second example is not valid, in Vanilla JS you do it like this:

  document.getElementsByTagName('p').filter(function(el) {
    el.innerHTML = 'Hello.';
  });


The right way is this :)

Array.prototype.forEach.call(document.getElementsByTagName('p'), function(el) { el.innerHTML = 'Hello.'; });


I like how the end of that statement contains both a winking crooked-smile smiley next to black-eyed frown smiley.


Nope:

TypeError: document.getElementsByTagName("p").filter is not a function

Because you don't get an array, only something array-like.


And this discussion over how to write a trivial loop is why I stay far away from vanilla js unless performance absolutely forces me to optimize.


This is why I program with a code editor / interactive console that tells me these things as I'm typing :-)




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

Search: