主板鸣叫

    技术2022-07-11  131

    主板鸣叫

    You don't need a thousand lines of code to make a big difference in any coding language.  Oftentimes it's quite the opposite:  a few tiny code snippets can do a world of good and accomplish big things.  I asked my Twitter followers to tweet to me their favorite tiny snippets of code -- that's a bit difference to try to pack into 140 characters!  Here are my favorites from this round!

    您不需要一千行代码就可以在任何一种编码语言中产生很大的不同。 通常情况恰恰相反:一些小巧的代码片段可以成就一个美好的世界,并成就大事。 我要求我的Twitter关注者向我发送他们最喜欢的小片段代码-尝试打包成140个字符有点不同! 这是我这一轮的最爱!

    ES6阵列初始化 (ES6 Array Initialization)

    Here are a few clever ways to initialize an array with ES6:

    以下是一些使用ES6初始化数组的聪明方法:

    @davidwalshblog Initialize an array with a default value (#ES6): > Array.from({ length: 7 }, _ => 42); [42, 42, 42, 42, 42, 42, 42]

    — Jeremy Martin (@jmar777)

    @davidwalshblog使用默认值( #ES6 )初始化一个数组:> Array.from({length:7},_ => 42); [42、42、42、42、42、42、42]

    —杰里米·马丁(@ jmar777) November 12, 2014 2014年11月12日

    @davidwalshblog Similarly, initialize w/ 1-N: > var oneToN = n => Array.from({ length: n }, (_, i) => i + 1); > oneToN(5); [1, 2, 3, 4, 5]

    — Jeremy Martin (@jmar777)

    @davidwalshblog类似地,用1-N初始化:> var oneToN = n => Array.from({length:n},(_,i)=> i + 1); > oneToN(5); [1、2、3、4、5]

    —杰里米·马丁(@ jmar777) November 12, 2014 2014年11月12日

    Short syntax for dynamic result!

    动态结果的简短语法!

    用inner / outerHTML删除包装HTML (Remove Wrapping HTML with inner/outerHTML)

    This neat little trick allows you to remove a wrapping element and re-parent the child in one operation.

    这个巧妙的小技巧可让您删除一个包装元素,并在一个操作中重新给孩子父母。

    @davidwalshblog `elem.outerHTML = elem.innerHTML;` removes wrapping `elem`.

    — Otto Rask (@ojrask)

    @ davidwalshblog`elem.outerHTML = elem.innerHTML;`删除包装的`elem`。

    — Otto Rask(@ojrask) November 12, 2014 2014年11月12日

    Of course you would brick your event connections but this is a neat trick.

    当然,您可以建立事件连接,但这是一个巧妙的技巧。

    3D人体元素 (3D Body Elements)

    Want a 3D look at a page's elements?  Check out this sweet JavaScript snippet:

    想要3D外观页面的元素吗? 查看这个甜蜜JavaScript代码段:

    @davidwalshblog t='transform';$('body').css({perspective:999}).css(t,'preserve-3d').children().css(t,'translateZ(-500px) rotateY(30deg)');

    — David Khourshid (@DavidKPiano)

    @davidwalshblog t ='transform'; $('body')。css({perspective:999})。css(t,'preserve-3d')。children()。css(t,'translateZ(-500px)rotationY (30deg)');

    — David Khourshid(@DavidKPiano) November 12, 2014 2014年11月12日

    This is a really neat optical effect, though not the most practical of snippets.

    尽管不是最实用的代码片段,但这确实是一种整洁的光学效果。

    YOLO! (YOLO!)

    Since `sudo` gives you the ultimate of powers, why not give it a YOLO alias?

    既然“ sudo”赋予了您最终的权力,为什么不给它一个YOLO别名呢?

    @davidwalshblog `alias yolo= 'sudo'` is always fun

    — Ian Fleming (@iangfleming)

    @davidwalshblog`alias yolo ='sudo'`总是很有趣

    — Ian Fleming(@iangfleming) November 12, 2014 2014年11月12日

    Hilarious!

    搞笑!

    Thank you to everyone who participated, and keep your tiny snippets for the next Tweet for Code!

    感谢所有参与的人,并保留您的小片段,以备下一稿代码使用!

    翻译自: https://davidwalsh.name/tweet-code

    主板鸣叫

    相关资源:电脑常见问题与故障1000例(高清PDF中文版)
    Processed: 0.263, SQL: 9