下一代Javascript: 卖弄单行代码
来源:互联网 发布:python调用adb命令 编辑:程序博客网 时间:2024/04/29 04:34
Here is a collection of ES6 one liners to show off!
NodeList to Array:
var headings = [ ... document.querySelectorAll('h1') ];
Unique Arrays:
[ ...new Set(array) ]
Destructuring:
var {foo, bar} = {foo: "lorem", bar: "ipsum"};// foo => lorem and bar => ipsum
Swap like a snake:
[a,b] = [b,a]
Max in array?:
Math.max(...array);
List comprehension:
[ for (value of ["Harriet", "178"]) value ].join(" was ");// Would give us "Harriet was 178"// BTW it was Charles Darwin's tortoise.
_map?
[{id: 1}, {id: 2}].map(x => x.id)// [1,2]
Object.isz!
let Object.isz = (x, y) => x === y || Object.is(x, y);//^ Credits to Mark S. Miller.
Is it a hidden file?:
isHidden = (file) => /^\.|~$/.test(file);isHidden(".DS_STORE") // true
Repeat with me:
(0/0+"").repeat("7")+ " BatMan!"// "NaNNaNNaNNaNNaNNaNNaN BatMan!"
If you are using some, please do let me know!Hope it did blew your mind! ;)
原文:http://h3manth.com/new/blog/2014/es6-one-liners-to-show-off/
0 0
- 下一代Javascript: 卖弄单行代码
- 下一代javascript
- SWIFT中的单行代码
- Swift单行代码
- 下一代javascript的几个特性
- android 单行代码实现功能
- 不要向用户卖弄技术
- 技术不精,不敢卖弄。。。
- 【转】我心目中的下一代JavaScript
- Nashorn:JVM上的下一代javascript引擎
- javascript 单行内容连续滚动,允许停留
- [代码]带停顿的单行滚动文字
- jQuery单行循环滚动展示代码
- ios7 alert中输入单行文本代码
- 10个惊艳的Swift单行代码
- 10个惊艳的Swift单行代码
- 10个惊艳的Swift单行代码
- 10个惊艳的 Ruby单行代码
- GL音乐播放器--代码实现<二>
- Android开发环境搭建教程
- Eclipse启动提示Failed to load the JNI shared library JVM.dll
- android animation中的参数interpolator详解
- 添加、删除HTML元素
- 下一代Javascript: 卖弄单行代码
- 大中华区FPGA工程师薪酬TOP15公司
- 【java】七种排序方法及时间测试
- ns-3构建简单点对点网络
- C标签使用EL表达式判断例子 不定期更新
- hdu1035.Robot Motion
- android中bindService的使用
- Java中@Override的作用
- rtl-ui-2