The publisher statement in publish/subscribe mode converts arguments to an array.
VaR ARGs = array. Prototype. Slice. Call (arguments, 0 );
This kind of built-in object prototype call can be used;
The "internal object prototype cannot be modified" as required in the encoding specification is similar to the following:
String.prototype.startsWith = function(text) { return this.indexOf(text) == 0; }
Arguments is an object.. It has [0], [1], length, which cannot represent an array, and it has other things.
Array arguments
function fn() { console.log(typeof arguments); //object console.log(arguments instanceof Array); //false for(var i = 0; i < arguments.length;i++) { console.log(arguments[i]); } var arr = [1,2,3]; console.log(arr); }
There isForeachUsage
function showResults(value, index) { console.log(‘value:‘ + value); console.log(‘index:‘ + index); }
var arr = [‘nihao‘, ‘nibuhao‘, ‘nihaobuhao‘];
arr.forEach(showResults);
//console.log
Value: nihao
Index: 0
Value: nibuhao
Index: 1
Value: nihaobuhao
Index: 2
Arguments cannot use foreach
function fn() { arguments.forEach(showResults); } function showResults(value, index) { console.log(‘value:‘ + value); console.log(‘index:‘ + index); } fn(‘nihao‘, ‘nibuhao‘); //Uncaught TypeError: undefined is not a function
Call of built-in object prototype