Hacker News new | past | comments | ask | show | jobs | submit login
7 KB front-end framework with many common features (github.com/radogado)
2 points by rado on Feb 28, 2014 | hide | past | favorite | 2 comments



TBH, it doesn't look too good. The syntax is all over the place, bad indentation, missing semicolons, a loop variable is leaking, it doesn't follow common conventions... But don't give up, keep improving your skills. Here's a replacement for that monstrous "getURLParameters" to pique your curiosity that can save you a few more lines:

  function getURLParameters(url) {
    var res = {},
        re = /[?&]([^?&]+)=([^?&]+)/g;
    url.replace(re, function(_,k,v) {
      res[k] = v;
    });
    return res;
  }
Then use it like "getURLParameters(window.location)".

Also just a tip in general, if you're up for some more constructive criticism I'll rewrite your "hasclass" function following conventions. So it goes from this:

  function hasclass (el, className) {
    if (el.classList)
      return el.classList.contains(className);
    else
      return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
  }
To this:

  function hasClass(el, className) {
    if (el.classList) {
      return el.classList.contains(className);
    }    
    return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
  }
Notice the camel casing in "hasClass", the braces around "if", and the early return.


Thanks for the great reply!




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

Search: