奇怪的JavaScript代码

前端之家收集整理的这篇文章主要介绍了奇怪的JavaScript代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我找到了这段代码
  1. ;
  2. 100% function($) { // WTF?
  3. var _true_ = true; // WTF?
  4. var _false_ = false; // WTF?
  5. var go = function(location,date) {
  6. location || (location = {});
  7. var result = _false_;
  8. if (date && date.day) {
  9. result = geoService.go(location,date);
  10. }
  11. return !!result;
  12. }
  13. var process = function(func) {
  14. var args = [].prototype.slice.call(arguments,1);
  15. return function() {
  16. return func.apply(this,args);
  17. }
  18. }
  19. // ...
  20. }(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的使用的注意.再次,这是非常奇怪的,而不是我以前见过的东西.

猜你在找的JavaScript相关文章