I have two arrays which I want to match them together as below:
var a = [1, 2, 3, 4];
var b = [5, 6, 7, 8];
This method works:
for ( var i = 0; i < 4; i += 1 ) {
(function(z) {
var d = x(a[z], b[z]);
})(i);
}
function x(j, k) {
console.log(j, k);
};
But I also want this method to work as well:
for ( var i = 0; i < 4; i += 1 ) {
(function(z) {
var d = x.y(a[z], b[z]);
})(i);
}
var x = {
y: function(j, k) {
console.log(j, k);
}
};
Upon testing it throws error.
I woulds use the second method because most of my JavaScript code adopting the pattern.