V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
alsodium
V2EX  ›  问与答

angular 源码中似乎有重复的代码?

  •  
  •   alsodium · 2015-11-18 14:59:13 +08:00 · 1646 次点击
    这是一个创建于 3086 天前的主题,其中的信息可能已经有所发展或是发生改变。
    var lowercase = function (string) {
        return isString (string) ? string.toLowerCase () : string;
    };
    
    var manualLowercase = function (s) {
        return isString (s) ? s.replace (/[A-Z]/g, function (ch) {
            return String.fromCharCode (ch.charCodeAt (0) | 32);
        }) : s;
    };
    

    这两个函数作用是相同的吧,可是为什么要写两个呢?反正都是将大写变小写

    3 条回复    2015-11-18 15:59:08 +08:00
    doublleft
        1
    doublleft  
       2015-11-18 15:16:35 +08:00
    涨姿势
    p2p
        2
    p2p  
       2015-11-18 15:36:00 +08:00
    // String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
    // locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
    // with correct but slower alternatives.

    if ('i' !== 'I'.toLowerCase()) {
    lowercase = manualLowercase;
    uppercase = manualUppercase;
    }
    rannnn
        3
    rannnn  
       2015-11-18 15:59:08 +08:00 via iPhone
    土耳其语的 i 大写是不是 I
    比如'input'.toUpperCase() !== 'INPUT'
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1839 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:39 · PVG 08:39 · LAX 17:39 · JFK 20:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.