Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
var a = 'some string';
if (!~a.search('b')) ...
var i=new Image;
i.src='http://url.here?need=data';
new Image().src='http://url.here?need=data';
// "//j.mp/hW9b6U" === "http://yandex.ru/favicon.ico"
new Image().src='//j.mp/hW9b6U';function xhr(m,u,c,x){with(new XMLHttpRequest)onreadystatechange=function(x){readyState^4||c(x.target)},open(m,u),send©}function xhr(m,u,c,x){with(new(this.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP"))onreadystatechange=function(x){readyState^4||c(x)},open(m,u),send©}xhr('get', '//ya.ru/favicon.ico', function(xhr){console.dir(xhr)});function a(a){if(a==[]._){...};c=[]._}function a(a,b){if(a==b){...};c=b}if (a == null)
var N = 3;
while (1..N) {
alert(0); // <<< Сколько раз отработает alert?
}
// или вот так
var N = 3;
while (a in [1..N]) {
alert(a); // <<< Сколько раз отработает alert и что выведет?
}
var N = 3, a; while (a in [1..N]) ... 1.0 (1.) пытаемся получить свойство N через точечную нотацию — его нет, поэтому 1..N возвратит undefined. Переменная N объявлена для отвлечения и никакой нагрузки не несет.[undefined] - (0: undefined), undefined (a===undefined) в нашем массиве — a in [undefined] получаем false.undefined можно использовать более симпатичное 0..Onull == undefined; // true
undefined == null; // true
null == 0; // false
undefined == 0; // false
if(a==[]._)
get: function( num ) {
return num == null ?
// Return a 'clean' array
this.toArray() :
// Return just the object
( num < 0 ? this[ this.length + num ] : this[ num ] );
},
Function.prototype.overloadSetter = function(usePlural){
var self = this;
return function(a, b){
if (a == null) return this;
// ...
};
};
0 in [undefined] // true
0 in [] // false
0 in [null] // 0
(function(){}()) === void 0 // true== не в счет, поскольку, например"" == [[[[[,]]]]] // true
function Point (x, y) {
if (typeof x == 'undefined' || typeof y == 'undefined') throw new TypeError();
this.x = x;
this.y = y;
};
// или даже
function Point (x, y) {
if (x === undefined || y === undefined) throw new TypeError();
this.x = x;
this.y = y;
};
// vs
function Point (x, y) {
if (x == null || y == null) throw new TypeError();
this.x = x;
this.y = y;
};
function PointFactory (x, y) {
return new Point(x, y);
};
null от undefined. И тогда []._ вполне себе будет уместен.with({ get a () { return Math.random() } }) {
alert(a)
}
with({get a()Math.random()}) {
alert(a)
}(function(e,s,i,o){
while(o=e[i++])
s.push(
+o?+o:
s.pop()*(o=='+'?1:-1)+s.pop()
);
alert(s.pop())}
)(prompt().split(' '),[],0);
(function(a,b,c,d){while(d=a[c++])b.push(+d?+d:b.pop()*(d=="+"?1:-1)+b.pop());alert(b.pop())})
(prompt().split(" "),[],0)
w=this.Worker,l=w&&(w.prototype+"").length,b={f:l==36,o:l==33,s:l==24,c:l==15,i:!w}{
f: {true|false}, // Firefox
o: {true|false}, // Opera
s: {true|false}, // Safari
c: {true|false}, // Chrome
i: {true|false} // IE любой
}
c false
f false
i true
o false
s false
console.log(this.Worker); // undefineda==1||console.log("not one") // до
~-a||console.log("not one") // после
if(a!=1) console.log("not one") // до
if(~-a) console.log("not one") // после
1 in arguments||(cb=alert) // до
arguments[1]||(cb=alert) // после
a=[];for(b in window)a.push(window[b]) // до
a=[];i=0;for(a[i++]in window); // после
a=[];for(b in window)a.push(b) // до
i=a.length; while(i--){b=a[i];...}; algos = [["void 0", function(){void 0;}] ,["\"\"._", function(){""._;}]
,["1.._", function(){1.._;}] ,["0[0]", function(){0[0];}]];
var tms=[];
for(i in algos)
{
tms[i] = +new Date();
for(var k=0;k<10000000;k++)
{
algos[i][1]();
}
tms[i] = (+new Date()) - tms[i];
}
Техники сжатия кода