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

这个前端代码太鬼畜了,完全看不懂了~有大神说一下吗?

  •  
  •   WytheHuang · 2016-12-28 23:09:22 +08:00 · 4573 次点击
    这是一个创建于 2886 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码如下: (f =>(x => f(y => x(x)(y)))(x => f(y => x(x)(y))) )(get => node => Array.from(node.childNodes) .filter(node => node.nodeType === Node.ELEMENT_NODE).reduce((depth, node) => Math.max(depth, get(node) + 1), 1) )(document.documentElement)

    微博链接: http://weibo.com/1074886493/EodjO45ln?type=comment#_rnd1482937548088

    15 条回复    2017-01-02 21:54:14 +08:00
    hxsf
        1
    hxsf  
       2016-12-28 23:53:46 +08:00 via iPhone
    手机阅读。没啥格式化工具。

    目测是遍历 dom 树 返回最大深度

    关键字
    箭头函数 立即执行函数
    exoticknight
        2
    exoticknight  
       2016-12-29 00:05:47 +08:00
    去看看 Y Combinator ,然后应该就懂了……
    xcatliu
        3
    xcatliu  
       2016-12-29 00:37:13 +08:00
    不知道把代码写成这样有什么意义
    alexsunxl
        4
    alexsunxl  
       2016-12-29 01:13:07 +08:00
    作用就跟一楼说那样了, 获得 dom 树最大深度
    其实执行一下就知道了, 一般这种就是从右往左边看
    附图
    lijsh
        5
    lijsh  
       2016-12-29 02:29:13 +08:00
    美化一下:
    (f =>
    (x => f(y => x(x)(y)))
    (x => f(y => x(x)(y)))
    )
    (get =>
    node =>
    Array.from(node.childNodes)
    .filter(node => node.nodeType === Node.ELEMENT_NODE)
    .reduce((depth, node) => Math.max(depth, get(node) + 1), 1)
    )
    (document.documentElement)

    (f =>
    (x => f(y => x(x)(y)))
    (x => f(y => x(x)(y)))
    )
    这种形式是 Y Combinator ,作用是让匿名函数递归自身。

    node =>
    Array.from(node.childNodes)
    .filter(node => node.nodeType === Node.ELEMENT_NODE)
    .reduce((depth, node) => Math.max(depth, get(node) + 1), 1)

    这里就是找 node 的后代元素嵌套深度的,后面把 document.documentElement 传进来。
    lijsh
        6
    lijsh  
       2016-12-29 02:30:00 +08:00
    本想美化一下,没想到排版还是瞎眼…
    yidinghe
        7
    yidinghe  
       2016-12-29 09:23:02 +08:00
    试下 markdown

    ```
    function(abc) {
    alert("Hello!");
    }
    ```
    apoclast
        8
    apoclast  
       2016-12-29 13:10:05 +08:00
    注意力从前端挪走几年了. 现在浏览器支持的 javascript 引擎是什么版本? 什么样的浏览器能支持这种函数式的 js 语法?
    se77en
        9
    se77en  
       2016-12-29 14:01:04 +08:00
    @apoclast 主要的浏览器现在都支持了,而且 ES6 规范里规定了 tail call optimization
    kopp123
        10
    kopp123  
       2016-12-29 17:00:16 +08:00
    这还算鬼畜。这才叫鬼畜
    [][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+[+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]])()
    lslqtz
        11
    lslqtz  
       2016-12-29 17:06:12 +08:00
    @kopp123 居然真的能执行哈哈哈哈哈哈哈
    mentalidade
        12
    mentalidade  
       2016-12-29 18:14:38 +08:00
    @kopp123 可怕,试了下真可以
    KIDJourney
        13
    KIDJourney  
       2016-12-29 20:47:40 +08:00 via Android
    jsfuck
    Damn
        14
    Damn  
       2016-12-29 23:30:08 +08:00 via Android
    @kopp123 卧槽,神马原理。。
    palmers
        15
    palmers  
       2017-01-02 21:54:14 +08:00
    箭头函数没有原函数语法清晰 我觉得
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2750 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:08 · PVG 12:08 · LAX 20:08 · JFK 23:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.