function Vector(x, y) {
this.x = x;
this.y = y;
}
Vector.prototype.plus = function plus(otherVector) {
var x = this.x + otherVector.x;
var y = this.y + otherVector.y;
return new Vector(x, y);
};
Vector.prototype.minus = function minus(otherVector) {
var x = this.x - otherVector.x;
var y = this.y - otherVector.y;
return new Vector(x, y);
};
Vector.prototype.toString = function toString() {
return 'Vector { x: ' + this.x + ', y: ' + this.y + ' }';
}
console.log(new Vector(1, 2).plus(new Vector(2, 3)));
var clients = JSON.parse(body.toString()).data
modules.define('clients', function(provide){
provide({
getClients() { //неименнованные функции - плохо для отладки, поэтому меняем на es2015 метод
/* Получаем список суб-клиентов агенства (или представителей) */
var sendQ = {
"method": "GetClientsList",
"token": ""
};
var options = {
url: "САЙТ",
method: "POST",
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Authorization': 'Bearer'
},
json: true,
body: sendQ
};
//удалить, оно тут не надо
//var clients = '';
return new Promise((resolve, reject) => request(options, (err, res, body) => {
if(err) {
return reject(err); //прокидываем ошибку в промис
}
var clients = JSON.parse(body.toString()).data;
var client = clients.map(a => a.Login);
if(!client[0]) {
console.log('Client list getty - OK - ' + client[0]);
resolve(client[0]); //возвращаем client[0] из промиса
} else {
console.log('some problems');
reject(new Error('some problems'));
};
})).then(client => {
/* Список получен переходим к дальнейщим действиям */
}).catch(err => {
/* здесь обрабатываем ошибку */
});
}
});
});
if (scores[i] > highScores) {
highScores = scores[i];
}
request.post({
url: `${url}/small.png`,
body: fs.createReadStream(`${fixtures}/small.png`),
headers: {
'Content-type': mime.lookup(`${fixtures}/small.png`),
'x-filename': 'small.png'
}
}, (error, response, body) => { /* Ваш код */ });
примерно так function calculateString(str) {
return (new Function('return ' + str))();
}
Можно и через eval, но eval еще медленнее чем new Function и к тому же отключает оптимизациюnew Intl.DateTimeFormat('en', {timeZone: 'UTC'}).format(new Date())
function num(v) {
znah_1.value += v;
}
будет вносить числа в левое поле<input type="button" value=" 0 " onclick="num(0)">
<input type="button" value=" 1 " onclick="num(1)">
Остальные инпуты поправьте по аналогии