我找到了这段代码:
- ;
- 100% function($) { // WTF?
- var _true_ = true; // WTF?
- var _false_ = false; // WTF?
- var go = function(location,date) {
- location || (location = {});
- var result = _false_;
- if (date && date.day) {
- result = geoService.go(location,date);
- }
- return !!result;
- }
- var process = function(func) {
- var args = [].prototype.slice.call(arguments,1);
- return function() {
- return func.apply(this,args);
- }
- }
- // ...
- }(jQuery,undefined);
在这里:http://www.dofactory.com/products/javascript-jquery-design-pattern-framework
(对不起,页面上没有找到id-s)
我不明白这些部分在做什么:
>第二行的“100%”
> var _true_ = true;和var _false_ = false;分配3-4行
我很好奇,这些的目的是什么.
解决方法
the “100%” in the second line
它是数字100,后跟模数运算符.除了强制右侧被视为函数表达式而不是函数声明之外,它不用于任何东西(因为结果未被捕获).
这是一种我从未见过的非常罕见且不直观的方法.
通常将函数表达式包装在parens中或在其前面加上not运算符.
the var true = true; and var false = false; assignments in the 3-4 lines
作者似乎试图通过将它们复制到名称中包含非字母数字字符而不是整个字面值的变量来引起对true和false的使用的注意.再次,这是非常奇怪的,而不是我以前见过的东西.