Making a short alias for document.querySelectorAll

前端 未结 9 1625
面向向阳花
面向向阳花 2020-12-12 14:48

I\'m going to be running document.querySelectorAll() a whole lot, and would like a shorthand alias for it.

var queryAll = document.querySelectorAll

queryAll         


        
9条回答
  •  时光说笑
    2020-12-12 15:36

    This would work, you need to invoke the alias using call() or apply() with the appropriate context.

    func.call(context, arg1, arg2, ...) 
    func.apply(context, [args]) 
    
    var x = document.querySelectorAll;
    x.call(document, 'body');
    x.apply(document, ['body']);
    

提交回复
热议问题