function Calc() {
let state = {};
let digits = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
for (let i = 0, l = digits.length; i < l; i++) {
Object.defineProperty(this, digits[i], {
get: function() {
if (!state.o) {
state.v = i;
return this;
}
if (state.o === 'plus') state.v = state.v + i;
if (state.o === 'minus') state.v = state.v - i;
if (state.o === 'times') state.v = state.v * i;
if (state.o === 'divide') state.v = state.v / i;
return this;
}
});
}
let operations = ['plus', 'minus', 'times', 'divide'];
for (let i = 0, l = operations.length; i < l; i++) {
Object.defineProperty(this, operations[i], {
get: function() {
state.o = operations[i];
return this;
}
});
}
this.value = function() {
let {v} = state;
state = {};
return v;
};
}
let calc = new Calc();
console.log(calc.one.plus.two.value()); // 3
console.log(calc.one.minus.four.value()); // -3
console.log(calc.one.plus.one.minus.two.value()); // 0
console.log(calc.one.value()); // 1
class Slider {
constructor({images, btnPrev, btnNext, rate, time}) {
this.images = document.querySelectorAll(images);
this.btnPrev = btnPrev;
this.btnNext = btnNext;
this.rate = rate;
this.time = time || 1000;
this.counter = 0;
document.querySelector(this.btnPrev).onclick = this.prev.bind(this);
document.querySelector(this.btnNext).onclick = this.next.bind(this);
if (this.rate) {
setInterval(this.next.bind(this), this.time);
}
}
prev() {
this.images[this.counter].classList.remove("showed");
this.counter--;
if (this.counter < 0) {
this.counter = this.images.length - 1;
}
this.images[this.counter].classList.add("showed");
}
next() {
this.images[this.counter].classList.remove("showed");
this.counter++;
if (this.counter >= this.images.length) {
this.counter = 0;
}
this.images[this.counter].classList.add("showed");
}
}
+function(param1, param2) {
console.log(param1);
}(10, 20);
function checkProps(obj, props) {
if (!obj) return false;
let value = obj;
for (let i = 0, l = props.length; i < l; i++) {
value = value[props[i]];
if (value == null) return false;
}
return true;
}
if (checkProps(campaign, ['budget', 'bills', 'type'])) {}
var n = 0;
var m = 25;
var result = [];
while(n < m) {
result.push(API.users.get({user_ids: n}));
n = n + 1;
}
return result;
class function upd<T>(SQL: string; params: array of Variant): Variant; static;
...
function TForm1.upd<T>(SQL: string; params: array of Variant): Variant;
begin
...
DataModule1.UniConnection1.ExecSQLEx(SQL, params);
DataModule1.UniConnection1.Commit;
...
end;