function sum(...args) {
return args.reduce((acc, val) => acc + val);
}
function mul(...args) {
return args.reduce((acc, val) => acc * val);
}
function applyAll(func, ...values) {
return func(...values);
}
alert( applyAll(sum, 1, 2, 3) ); // 6
alert( applyAll(mul, 2, 3, 4) ); // 24
alert( applyAll(Math.max, 2, -2, 3) ); // 3
alert( applyAll(Math.min, 2, -2, 3) ); // -2 import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const createRouter = () => new Router({
mode: 'history',
routes: []
})
const router = createRouter()
export function resetRouter () {
const newRouter = createRouter()
router.matcher = newRouter.matcher // the relevant part
}
export default routerconst fs = require('fs');
module.exports.index = function (req, res, next) {
fs.createReadStream('./src/pages/index.html').on('error', next).pipe(res);
});import htmlString from 'raw-loader!./src/pages/index.html'; sum(0)(...)(n) всегда возвращает функцию falert принимает на вход строку, поэтому в момент вызова alert выполняется автоматическое преобразование функции f к строке. По умолчанию метод f.toString функции вернул бы текст ее исходного кода, но для функции f метод был преопределен и теперь он возвращает значение currentSum из замыкания.console.log( Number(sum(5)(-5)) );console.log( Boolean(sum(5)(-5)) );ymaps.ready(init.bind(this));
function init() {
this.city1 = 'sdf';
}ymaps.ready(() => {
this.city1 = 'sdf';
});this.city1, можно использовать this.$data.city1 decodeURIComponent(escape('Bj\u00c3\u00b6rn H\u00c3\u00bcttner'))/**
* Decodes utf-8 encoded string back into multi-byte Unicode characters.
*
* Can be achieved JavaScript by decodeURIComponent(escape(str)),
* but this approach may be useful in other languages.
*
* @param {string} utf8String - UTF-8 string to be decoded back to Unicode.
* @returns {string} Decoded Unicode string.
*/
function utf8Decode(utf8String) {
if (typeof utf8String != 'string') throw new TypeError('parameter ‘utf8String’ is not a string');
// note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
const unicodeString = utf8String.replace(
/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
function(c) { // (note parentheses for precedence)
var cc = ((c.charCodeAt(0)&0x0f)<<12) | ((c.charCodeAt(1)&0x3f)<<6) | ( c.charCodeAt(2)&0x3f);
return String.fromCharCode(cc); }
).replace(
/[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
function(c) { // (note parentheses for precedence)
var cc = (c.charCodeAt(0)&0x1f)<<6 | c.charCodeAt(1)&0x3f;
return String.fromCharCode(cc); }
);
return unicodeString;
}err.toString(), a err.stack, значит вопрос в том откуда берется этот stacksuper(message, 404, 2);super(message);this.stack - строка которая начинается с Error: Ресурс не найден!super(message); Меняется имя this.name = 'APIError'; После этого статический метод Error.captureStackTrace перезаписывает свойство this.stack на сей раз уже используя имя 'APIError', теперь this.stack начинается с APIError: Ресурс не найден!this.name = 'Error404';, но в строке this.stack так и остается APIError: Ресурс не найден!name в прототипAPIError.prototype.name = 'APIError';
Error404.prototype.name = 'Error404';if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error()).stack;
}this.stackError устанавливает геттер затем используется ленивое вычисление, и если его не трогать раньше времени, то получится ожидаемое значение.