Tag Archives: javascript

Javascript Books

Blog Post: https://plus.google.com/115133653231679625609/posts/H3onog42Msj?utm_source=javascriptweekly&utm_medium=email =========== http://shop.oreilly.com/product/9780596805531.do http://www.amazon.de/Effective-JavaScript-Specific-Software-Development/dp/0321812182/ref=sr_1_2?ie=UTF8&qid=1356887062&sr=8-2 https://leanpub.com/oopinjavascript http://www.amazon.com/Past-Present-Future-JavaScript-ebook/dp/B008MYLN3Y http://shop.oreilly.com/product/0636920018421.do http://www.amazon.com/gp/product/1593272820?ie=UTF8&tag=marijhaver-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1593272820

Mixin ECMAScript 5 compatible

There is a small difference between ECMAScript 3 and 5 described here: http://www.nczonline.net/blog/2012/12/11/are-your-mixins-ecmascript-5-compatible/?utm_source=javascriptweekly&utm_medium=email Solution: function mixin(receiver, supplier) { if (Object.keys) { Object.keys(supplier).forEach(function(property) { Object.defineProperty( receiver, property, Object.getOwnPropertyDescriptor(supplier, property) ); }); } else { for (var property in supplier) { if (supplier.hasOwnProperty(property)) { receiver[property] = supplier[property]; } } } }

Color validation

function validateColor(color) { var el, result;   el = document.createElement("div"); el.style.backgroundColor = "white";   document.body.appendChild(el);   el.style.backgroundColor = color; result = el.style.backgroundColor; el.parentNode.removeChild(el);   return color === "white" || result !== "white"; }   validateColor(’white’);

Garbage Collector and performance

Try to aviod “delete” Be aware of that browsers engines tries to optimize “hot” objects (heavly used), and using delete you are descreasing performace. var obj = {foo : 1}; delete obj.foo; Think about the scope Instead of nulling global variables, just use a function-local variables that goes out of scope when it’s no longer… Read More »

Checking if viewport has correct size

var wmq = window.matchMedia("(min-width: 400px)"); if (wmq.matches) { /* the view port is at least 400 pixels wide */ } else { /* the view port is less than 400 pixels wide */ } Event listener: wmq.addListener(function(wmq) { console.log(wmq.media + " " + (wmq.matches ? ‘matches’ : "doesn’t match")); }); Suppored in all browsers. (IE10+)