+'10' + +'10'
- сложить строки как числа (в этом примере ответ будет 20).value1 || value2
- используется для возвращения из функции какого-то результата (value1 если имеет !!value = true или value2), так-же можно записывать в переменную таким образом какое-то из значений, например:var foo = bar || test;
function fooTest(arg1, arg2){
return arg1 || arg2;
}
fooTest(10, 40) = 10;
fooTest(undefined, 40) = 40;
// Возвести число в квадрат в случае если оно больше 10.
function foo(x){
return x > 10
}
function bar(x){
return x*x;
}
function sqrdX(x){
return foo(x) && bar(x);
}
sqrdX(40) = 1600;
sqrdX(4) = false;
Array.isArray = function(obj) {
return /^\[object (NodeList|Array)\]$/.test(Object.prototype.toString.call(obj));
};
Document.prototype.addClass =
DocumentFragment.prototype.addClass =
NodeList.prototype.addClass =
Element.prototype.addClass = function(value) {
if( typeof value === "string" && value ) {
var j, current, clazz, finalValue;
var stripAndCollapse = function(v, a) {
var tokens = v.match(/[^\x20\t\r\n\f]+/g) || [];
return a ? tokens : tokens.join(" ");
}, classList = stripAndCollapse(value, true);
var list; Array.isArray(this) ? (list = this) : (list = [], list.push(this));
list.forEach(function(elem, i) {
// This expression is here for better compressibility (see addClass)
current = elem.nodeType === 1 && (" " + stripAndCollapse(elem.className) + " ");
if( current ) {
j = 0;
while( (clazz = classList[j++]) ) {
if( current.indexOf(" " + clazz + " ") < 0 ) {
current += clazz + " ";
}
}
// Only assign if different to avoid unneeded rendering.
finalValue = stripAndCollapse(current);
if( finalValue !== elem.className ) {
elem.setAttribute("class", finalValue);
}
}
});
}
return this;
};
Сам являюсь фронт-энд разработчиком, с бекендом не дружу.
<input
type="password"
name="password"
readonly
onfocus="this.removeAttribute('readonly')">