134// Filters helper: handles the use of preformated easilly translatable strings.
135// Source: https://www.tutorialstonight.com/javascript-string-format.php
136String.prototype.format = function () {
137 let args = arguments;138 return this.replace(/{([0-9]+)}/g, function (match, index) {
139 return typeof args[index] == 'undefined' ? match : args[index];
140 });
284
285// Applies a filter on a sequence of objects: {scope | select: 'name' | map: 'lower' | join: ', '}
286expressions.filters.map = function (input, filter) {
287 let args = Array.prototype.slice.call(arguments, 2);288 return input.map(x => expressions.filters[filter](x, ...args));
289};
290
There are rest parameters in ES2015
. We can use that feature for variadic functions instead of the arguments
variable.
arguments
does not have methods of Array.prototype
, so it's a bit of an inconvenience.
function foo() {
console.log(arguments);
}
function foo(action) {
var args = Array.prototype.slice.call(arguments, 1);
action.apply(null, args);
}
function foo(action) {
var args = [].slice.call(arguments, 1);
action.apply(null, args);
}
function foo(...args) {
console.log(args);
}
function foo(action, ...args) {
action.apply(null, args); // or `action(...args)`, related to the `prefer-spread` rule.
}
// Note: the implicit arguments can be overwritten.
function foo(arguments) {
console.log(arguments); // This is the first argument.
}
function foo() {
var arguments = 0;
console.log(arguments); // This is a local variable.
}