Today's the day

向软件大牛炫耀我会焊单片机,向硬件大牛炫耀我会写 Rails,向软硬件大牛炫耀我生物,向软硬件生物大牛炫耀我会折腾期货 -_-bbb

转战嵌入式
啥叫疯狂?

原来我的 Javascript 水平还不是最差的

galeki posted @ 2008年9月14日 14:13 in 乱七八糟 with tags javascript , 5099 阅读

早上洗好澡,坐在电脑前一边吃早饭一边上天涯逛,看了许久三 L 的相关帖子,心情很沉重。

随后跳到了国家质量监督总局的网站,习惯性的 Crtl+U 了一下,然后看到这么一句:

  1. if (3==2)    //把3==3改为3==2则弹出窗口不工作;改为3==3则工作。
  2. {
  3. popup = window.open('', 'popupnav', 'width=430, height=250, resizable=0, scrollbars=no');
  4. }

彻底被雷了一下……

g.zhen.ning 说:
2008年9月14日 17:34

一般处理这应该是用boolean是吧?
var = true
if var
..........
end

==
这样对么?

w33018 说:
2008年9月14日 18:44

应该定一个bool变量,名字叫做“最近国家不管网站弹出窗口”(JavaScript是支持中文变量名字的),在一个全局文件中控制值,这里只判断就可以了,于是可以改成:
if (最近国家不管网站弹出窗口)
{
popup = window.open('', 'popupnav', 'width=430, height=250, resizable=0, scrollbars=no');
}

Avatar_small
galeki 说:
2008年9月14日 23:35

@g.zhen.ning: 是啊,主要雷在注释上了。

@w33018: 这招不错~

TualatriX 说:
2008年9月15日 01:04

哈哈,真的好有意思喔!
编写这段的人好幽默!

Avatar_small
9700八哥 说:
2008年11月03日 21:21

刚开始我也跟着你嘲笑,但有兴趣跑到那个网站看了一下源码,我感觉……是你自作聪明了,咴儿咴儿
------------------------
这种写法有特殊用途,你可以想象吗?
查找-替换,没错,该代码3==3类似的有好几处,
就是这个网页当他需要改成3==2的时候,他查找替换很方便,但是如果写成true再全部替换成false,肯定会影响到代码的其他地方导致灾难性的后果。
--------------------------------------------------------------
因此我认为这是作者独具匠心的写法。

Avatar_small
9700八哥 说:
2008年11月03日 21:29

w33018 说滴方法是正规程序员的写法,
原作作者是用一种绮丽诡异的写法。
两者有异曲同工之妙,不过还是应该走正规道路哈哈。

Avatar_small
galeki 说:
2008年11月03日 22:46

是啊,w33018 已经回答你的问题了,定一个变量就不用查找替换了,意义也可以一目了然 :)。

其实我只是被那注释雷了一下,也没有嘲笑的意思啦,呵呵

wddfgeew 说:
2022年7月05日 19:56

Special BANGALORE Escort and Escort Listing site for elite gentlemen who want to spend time together with a quality Moscow escort lady. Bangalore Escorts service

MAHMISHAL 说:
2022年10月01日 17:35

Spot lets start work on this write-up, I actually believe this site needs much more consideration. I’ll apt to be once again to read a lot more, many thanks that info. <a href="http://alongnovember.com/">alongnovember.com</a>

MAHMISHAL 说:
2022年10月01日 17:35

Spot lets start work on this write-up, I actually believe this site needs much more consideration. I’ll apt to be once again to read a lot more, many thanks that info.alongnovember.com

MAHMISHAL 说:
2022年10月01日 17:35

Spot lets start work on this write-up, I actually believe this site needs much more consideration. I’ll apt to be once again to read a lot more, many thanks that info. [url=http://alongnovember.com/]alongnovember.com[/url]

MAHMISHAL 说:
2022年10月01日 17:36

Spot lets start work on this write-up, I actually believe this site needs much more consideration. I’ll apt to be once again to read a lot more, many thanks that info. alongnovember.com


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter