2

ES6 好棒!

 3 years ago
source link: https://blog.lilydjwg.me/2015/10/8/es6-is-pythonic.184811.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ES6 好棒!

本文来自依云's Blog,转载请注明。

SegmentFault 的通知页里的链接总是会在新标签页打开。这对于我来说就多了一个需要关闭的标签页——我本可以在最后一条新通知时不打开新标签页的。我习惯由我自己来控制链接在哪里打开,会根据情况选择在后台新标签页打开或者在当前标签页打开。SegmentFault 通知页这样子在前台标签页打开对于我来说除了烦人之外便毫无用处

然而 SegmentFault 改来改去,最终似乎还是决定像很多国内网站那样让我这种用户厌烦。罢了,是时候让油猴出场了。这次尽情使用 ES6 好了=w=

sf-enhancement.user.js
// ==UserScript==
// @name          SegmentFault Enhancement
// @description   SegmentFault Enhancement
// @include       http://segmentfault.com/*
// @include       https://segmentfault.com/*
// ==/UserScript==
// jshint moz:true
if(location.pathname === "/user/notifications"){
let elements = document.querySelectorAll('section.stream-list__item a[target]');
for(let el of elements){
el.removeAttribute('target');
}
}

虽然不是第一次使用let了,但for...of是第一次使用。这感觉好棒!跟写了好长时间的 C 之后发现表达力强大的 Python 一样!

现在的 ECMAScript 越来越像语法怪异的 Python 了呢 ;-)

PS: 在网页里写上在新标签页打开有安全隐患的。

发送到 Kindle


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK