Everyone knows (well almost everyone, my wife probably doesn't) that semicolons in Javascript are not necessary and I had a "pleasure" of maintaining Javascript file where most of the semicolons where missing. Programmer was relying on automatic semicolon insertion and had no idea what kind of problems this might cause. The script was working fine however relying on automatic insertion is dangerous and might lead to not-so-easy to find bugs. One example I can think of involves self-invoking functions. See the code below:
var drinkBeer = function () {
// gulp..gulp..gulp..
}
(function () {
})();
At the first glance there is nothing wrong with the code above. However when it runs the self invoking function will be passed as an argument to drinkBeer function declared above. Then drinkBeer will be invoked causing script to fail. As far as interpreter is concerned the code will look something like:
var drinkBeer = function () {
// gulp..gulp..gulp..
}(function () {
})();
..and BOOM! The problem can be easily fixed by inserting semicolon in the right place. This code below will make interpreter happy, you happy and your boss and will sure put you in place (or maybe not) for big promotion:
var drinkBeer = function () {
// gulp..gulp..gulp..
};
(function () {
})();
Sunday, November 24, 2013
Thursday, May 23, 2013
TABGuard jQuery plugin
Coding a web page it often happens that there is a need to limit number of elements that TAB will put in focus. Default browser behavior is to iterate over all the focusable elements on the page and then put elements in browsers chrome in focus so URL bar, search box, etc etc. It becomes a problem when e.g. having a dialog we need TAB to iterate only over elements contained in this dialog and nothing outside of it. Seeing how many people having problems with it I put together this tiny (~2kb minimised) jQuery UI plugin that limits elements that TAB fill focus on. Details and example of use can be found at https://github.com/spirytoos
and I hope someone will find it useful.
and I hope someone will find it useful.
Tuesday, February 19, 2013
To spin or not to spin?
Came up with an idea of cool interface where navigation works sort of like rotating disc that user can spin. Implemented it quickly and as it proved to be pretty awesome (especially on iPads) I decided to go a step further and use it for my portfolio. Its powered by HTML5,CSS5, jQuery and what not but beware! Older IE's will choke (and die hopefully, once and for all) but if you run newer browser you will be able spin the disc and see some of my work.
MaskIt jQuery plugin
I just published jQuery plugin that adds mask inside of input fields, limits what can be entered and do all this magic. Its free to use, works on IE7+ and is superawesome (according to me ;). Hope you like it and find it useful, find it here https://github.com/spirytoos.
Subscribe to:
Posts (Atom)