Slides from JSConf / phpied.com
Slides from JSConf / phpied.com
High Performance Kick Ass Web Apps (JavaScript edition)
View more Microsoft Word documents from Stoyan Stefanov.
Cleanup after yourself
property you no longer need
var myApp = {
prop: huge
};
delete myApp.prop
DOM elements you no longer need
var el = $('mydiv');
el.parentNode.removeChild(el);
instead of ...
function myEvent(el, type, fn) {
if (window.addEventListener) {
el.addEventListener(type, fn, false);
} else if (window.attachEvent) {
el.attachEvent('on'+type, fn);
} else {..}
}
Do ...
if (window.addEventListener) {
var myEvent = function (el, type, fn) {
el.addEventListener(type, fn, false);
} else if (window.attachEvent) {
var myEvent = function (el, type, fn) {
el.attachEvent('on' + type, fn);
}
}
}
Memoization
function myFunc (param) {
if (!myFunc.cache) {
myFunc.cache = {};
}
if (!myFunc.cache[param]) {
var result = {}; // ...
myFunc.cache[param] = result;
}
return myFunc.cache[param];
}
沒有留言:
張貼留言