This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript 字符串编码使用 UTF-16 | |
"💩".length === 2; | |
"💩" === "\u{1F4A9}"; // es6 | |
"💩" === "\uD83D\uDCA9"; // es5 | |
// 同一个编码可能使用不同的码位 | |
"ò" === "ò"; // ❎ | |
"ò" === "\xF2"; // ✅ | |
"ò" === "o\u0300"; // ✅ | |
"o\u0300".normalize("NFC") === "\xF2"; // ✅ es6 提供了 normalize 函数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// These are examples how to created PACKED_*_ELEMENTS arrays preinitialized | |
// in V8, following up on offline discussion at the last MunichJS meetup. | |
function createPackedViaArrayFrom(length, value) { | |
return Array.from.call(null, Array.prototype.map.call({length}, _ => value)); | |
} | |
function createPackedViaGenerator(length, value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
const a = new Int32Array(10); | |
for (let i = 0; i < 1e6; i++) { | |
a.set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | |
} | |
return a; | |
} | |
console.time('test'); | |
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
class Point { | |
getX() { | |
console.log(this.x); // C | |
} | |
} | |
class ColorPoint extends Point { | |
constructor() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ask the coffee machine at IP 192.168.2.2 to do its job | |
device('192.168.2.2') | |
.do( 'coffee' ) | |
.then( wakeMeUpCallback ) | |
// turn all lights on | |
device.findAll('light').do('turnOn') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convert a dom element to a PDF and download it | |
convert( $('.invoice') ).to( 'invoice.pdf' ).download() | |
// alternatively | |
download( convert( $('.invoice') ).to( 'invoice.pdf' ) ) | |
// convert another website to a png and show it on the page | |
convert( 'http://exam.pl/page' ).toImage().then( $('.screenshots').append ) | |
// attach a file to an email |
NewerOlder