V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
Debiancc
V2EX  ›  JavaScript

妈妈说好代码要分享-js

  •  
  •   Debiancc · 2014-11-05 14:19:30 +08:00 · 3353 次点击
    这是一个创建于 3461 天前的主题,其中的信息可能已经有所发展或是发生改变。
    //shortcut support. arrow-up arrow-down and enter event.
    if (event.which == keyMap.down || event.which == keyMap.up) {
    var direction = event.which == keyMap.down ? true : false,
    $activeSelector = $('.wcSingleUser.active'),
    $tmpSelector;

    //if current active selector has next or prev element and direction is matching
    //then execute switch active and keep unique
    if (((!!($tmpSelector = $activeSelector.next()) && direction)
    || (!!($tmpSelector = $activeSelector.prev()) && !direction))
    && $tmpSelector.length) {
    $activeSelector.removeClass('active');
    $tmpSelector.addClass('active');
    }
    return;
    }


    太美
    8 条回复    2014-11-10 10:37:42 +08:00
    Jaylee
        1
    Jaylee  
       2014-11-05 15:54:24 +08:00
    你想表达什么 ?
    cdxem713
        2
    cdxem713  
       2014-11-05 16:49:34 +08:00
    函数名是个啥,变量声明不放在函数头么?
    neutrino
        3
    neutrino  
       2014-11-05 16:53:12 +08:00
    @cdxem713 用的时候再声明变量是好习惯。
    cdxem713
        4
    cdxem713  
       2014-11-05 17:40:48 +08:00
    @neutrino js由于变量提升,其实在哪声明都跟在函数头声明是一样的,在函数头声明会安全些。用时重新初始化。
    vose
        5
    vose  
       2014-11-06 09:28:05 +08:00
    js 新手,不要脸问一下……这段函数是干嘛用?亮点是? 我也想体会一下呀,教练!
    cmy5001
        6
    cmy5001  
       2014-11-06 10:28:04 +08:00
    不明觉厉,简单两个判断可以完成的事,非要绕一大圈,这是逼格的体现?
    Debiancc
        7
    Debiancc  
    OP
       2014-11-10 10:37:12 +08:00
    @cmy5001 对的
    Debiancc
        8
    Debiancc  
    OP
       2014-11-10 10:37:42 +08:00
    @vose 目测下来是一个快捷键的support
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2965 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:26 · PVG 21:26 · LAX 06:26 · JFK 09:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.