收集一些自己喜欢的单词
// 格式化为es批量插入格式
[...$$('[itemprop=text] p')]
.map(v=>v.textContent)
.slice(1)
.map(v=>`{"create":{"_index":"ym","_type":"words","_id":"${v}"}}
{ "word":"${v}", "sentence":"", "def":"", "created":"2016-11-28"}`).join('\n')
收集一些自己喜欢的单词
// 格式化为es批量插入格式
[...$$('[itemprop=text] p')]
.map(v=>v.textContent)
.slice(1)
.map(v=>`{"create":{"_index":"ym","_type":"words","_id":"${v}"}}
{ "word":"${v}", "sentence":"", "def":"", "created":"2016-11-28"}`).join('\n')
"use strict"; | |
const net = require("net"); | |
const port = process.env.PORT || 44444; | |
const once = !!process.env.ONCE || false; | |
function echo(socket) { | |
const server = this; | |
const {remoteAddress, remoteFamily, remotePort} = socket; |
"use strict"; | |
const dgram = require("dgram"); | |
const port = process.env.PORT || 44444; | |
const once = !!process.env.ONCE || false; | |
const opts = {type: "udp4", reuseAddr: true}; | |
const socket = dgram.createSocket(opts, (msg, info) => { | |
// msg: Buffer, info: {address, family, port, size} |
This is a strawman proposal for adding pattern matching to ECMAScript. Pattern matching is useful for matching a value to some structure in a similar way to destructuring. The primary difference between destructuring and pattern matching are the use cases involved - destructuring is useful for binding pieces out of larger structures whereas pattern matching is useful for mapping a value's structure to data or a set of behaviors. In practice this means that destructuring tends to allow many shapes of data and will do its best to bind something out of it, whereas pattern matching will tend to be more conservative.
Additionally, the power of pattern matching is increased substantially when values are allowed to participate in the pattern matching semantics as a matcher as well as a matchee. This proposal includes the notion of a pattern matching protocol - a symbol method that can be implemented by objects that enables developers to use those values in pattern matching. A common scenario w
import java.util.Arrays; | |
import java.util.List; | |
public class FunWithStaticInitialization { | |
public static void main(String[] args) { | |
new SimpleThing(); | |
} | |
interface Thing { |
Some things that are "better" with this BetterPromise
implementation:
BetterPromise # then(..)
accepts a BetterPromise
(or Promise
) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.
var p = BetterPromise.resolve(42);
var q = Promise.resolve(10);
p.then(console.log).then(q).then(console.log);
{ | |
"presets": [ "es2015" ] | |
} |
"use strict"; | |
[foo,bar] = TNG(foo,bar); | |
// NOTE: intentionally not TNG(..) wrapping useBaz(), so that it's | |
// basically like a "custom hook" that can be called only from other | |
// TNG-wrapped functions | |
function foo(origX,origY) { | |
var [x,setX] = useState(origX); | |
var [y,setY] = useState(origY); |
var str = "The quick brown fox jumped over the box like an ox with a sox in its mouth"; | |
str.match(/\w(ox)/g); // ["fox", "box", "sox"] | |
// match (when used with a 'g' flag) returns an Array with all matches found | |
// if you don't use the 'g' flag then it acts the same as the 'exec' method. | |
str.match(/\w(ox)/); // ["fox", "ox"] | |
/\w(ox)/.exec(str); // ["fox", "ox"] |