这个问题在这里已有答案:
templateMain = {
pathname: './wp-content/themes/projectname',
js_libs: [
// jQuery
pathname + '/js/jQuery/jquery-3.1.1.js',
],
js: [
pathname + '/js/default.js'
]
};
如何在此javascript定义中对我的var templateMain.pathname进行范围调整?
你可以使用prototypes
:
var TemplateMain = (function() { })
TemplateMain.prototype.pathname = './wp-content/themes/projectname'
TemplateMain.prototype.js_libs = [TemplateMain.prototype.pathname + '/js/jQuery/jquery-3.1.1.js']
TemplateMain.prototype.js = [TemplateMain.prototype.pathname + '/js/default.js']
console.log(new TemplateMain())