I want to invoke a function using apply(), but when I pass a var with bracket notation, it does not work any more. Why this does not work? thanks
window.video['play'] = OK
window.video.play = OK
obj[p[i]] = not OK <= something like this I'd like to use
var obj = window;
var prop = 'video.play';
var p = prop.split('.');
for (var i = 0; i < p.length; i++) {
obj = obj[p[i]];
}
var orig = obj; // problem here with obj: window.video['play'] = OK, but obj[p[i]] = not OK
obj = function() {
var ar = Array.prototype.slice.call(arguments);
console.log(ar); // not work!
orig.apply(this, ar);
};
almost the same, but this works:
var orig = window.video.play;
window.video.play = function() {
var ar = Array.prototype.slice.call(arguments);
console.log(ar); // work!
orig.apply(this, ar);
};