javascript create alias for document.getElmentById, 通过apply修改this指向

* 通过apply修改this指向 

  window, 改为document

document.getElementById = function(fun) {
	return function() {
		return fun.apply(document, arguments);
	}
}(document.getElementById);
var getId = document.getElementById;

// usage:

getId("iusername");

但是这么写 是undefined

var byId = function(fun) {
    return function(id) {
        fun.call(document, id);
    };
}(document.getElementById);

var u = byId("iusername");
console.log(u);    // undefined

猜你喜欢

转载自blog.csdn.net/fareast_mzh/article/details/84323806
今日推荐