绕过 j/j
/*jshint strict: true */
var myModule = (function() {
"use strict";
var privVar = true,
pubVar = false;
function privFn() {
return this.test; // -> Strict violation.
}
function pubFn() {
this.test = public ; // -> Strict violation.
privFn.call(this); // -> Strict violation.
}
return {
pubVar: pubVar,
pubFn: pubFn
};
}());
myModule.pubFn();
我的理解是,在一项职能声明中使用<代码>即<>>ts造成这种情况,但我阅读了一些Crockford撰写的论文,他说,这种违反行为的目的是防止全球变化的污染,但此处唯一的全球变量是明确定义“
我如何能够采纳这种模式的想法?
<>Update: 如果我使用职能表述而不是声明,这似乎是工作,
var pubFn = function () { ...
I m not a fan of this format though, prefer to have the function name and named params closer and the declaration looks/feels cleaner. I honestly don t see why this is throwing the violation - there s no reason for it in this pattern.