我有一段代码,看起来像这样:
const $ = prototype;
(function($){
myFunc();
})(jQuery)
const myFunc = function () {
console.log($);
}
在这种情况下,输出将是prototype
. 但是我希望任何子函数都$
为jQuery。 请记住,这些函数有很多子函数。
我可以$
作为参数传递,也可以在每个子函数中定义一个新的局部常量。 有什么方法可以避免这种情况并使$ = jQuery
可用于所有子函数?
也许你正在寻找这样的东西
var previous = null;
var current = null;
const myFunc = function () {
console.log($);
console.log(this.v)
childfunc()
}
const childfunc = function(){
var $=this.v
console.log($)
childofchild()
}
const childofchild = function(){
var $=this.v
console.log($)
}
const $ = 'prototype';
(function($){
v=$
myFunc();
})('jQuery');