Let's talk about JavaScript
(function(){
'use strict';
var undefined = 42;
console.log(undefined);
})();
(function(globalWindow, undefined){
'use strict';
var undefined = 42;
console.log(undefined);
})(window);
Function.prototype.call=
(function(o){return function(){var r=o.apply(this,arguments);
if(typeof r=='number')return r+1;return r;}})
(Function.prototype.call);
+
DO YOU EVEN
BRO
Get the current vertical position of the scroll bar
var a = “12342234”, b, start = Date.now();
for (var i = 0; i < 1000; i++) {
b = ~~a;
}
console.log(Date.now() - start);
var a, b, start = Date.now();
for (var i = 0; i < 1000; i++) {
b = ~~“12342234”;
}
console.log(Date.now() - start);
var a, b, start = Date.now();
for (var i = 0; i < 1000; i++) {
b = 12342234;
}
console.log(Date.now() - start);
var start = Date.now();
for (var i = 0; i < 1000; i++) {
// sound of silence
}
console.log(Date.now() - start);
// use literal
var arr = [];
// instead of
var arr = new Array(16);
// use literal
var arr = [];
// instead of
var arr = new Array(16);
// put the array into dictionary mode
delete arr[15];
array['amazing'] = 'stuff';
function forInFunc() {
var dictionary = {'+': 5};
for (var key in dictionary);
}
function forEachFunc() {
var arrayOfObjects = [{}, {}, {}, {}, {}, {}];
arrayOfThings.forEach(function(obj) {
// code
}, this);
}