Array.prototype.ownMethod = function(x) {
x(this)
}
[1, 2, 3, 4].ownMethod(function(x) {
return x[1]
}) // This callback won't work .
I tried to pass array value inside my First-class function. This method won't work for me.
Array.prototype.ownMethod = function(x) {
x(this)
}
[1, 2, 3, 4].ownMethod(function(x) {
return x[1]
}) // This callback won't work .
I tried to pass array value inside my First-class function. This method won't work for me.
You've been caught out by Automatic Semicolon Insertion.
The function expression creates an object (the function) and the square bracket immediately after it is used as a property accessor instead of an array literal.
Add an explicit end of statement with a semi-colon to fix that.
Array.prototype.ownMethod = function(x) {
x(this)
};
[1, 2, 3, 4].ownMethod(function(x) {
console.log(x[1]);
})