Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Node.js v4 の話 #tng18
Search
Yosuke Furukawa
PRO
October 08, 2015
Programming
16
9.6k
Node.js v4 の話 #tng18
東京Node学園 18時限目で発表した Node.js v4 の話です
Yosuke Furukawa
PRO
October 08, 2015
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
150
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
340
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
700
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.3k
リアーキテクトと開発生産性について
yosuke_furukawa
PRO
25
9.6k
Other Decks in Programming
See All in Programming
初めてDefinitelyTypedにPRを出した話
syumai
0
400
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
530
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Ethereum_.pdf
nekomatu
0
460
CSC509 Lecture 12
javiergs
PRO
0
160
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Producing Creativity
orderedlist
PRO
341
39k
Rails Girls Zürich Keynote
gr2m
94
13k
Ruby is Unlike a Banana
tanoku
97
11k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Building Flexible Design Systems
yeseniaperezcruz
327
38k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Transcript
Node.js v4 @yosuke_furukawa
@yosuke_furukawa
Tokyo NodeFest 2012
None
I asked him …
%PZPVIBWFBQMBOUPSFMFBTF W /FYUZFBS NBZCF
Tokyo NodeFest 2012
Congrats!!!!
Node.js v4.x features
Lots of features………….
JavaScript Syntax/Features
ES2015
ES2015 • let/const • class • Map/Set/WeakMap/ WeakSet • Generators
• Binary/Octal literals • Symbol • Template String literals • String.prototype.repeat • @@toStringTag • Enhanced Object Literals • unicode literals • arrow functions
Your code will be changed in Node.js
MyEventEmitter // v0.12 ‘use strict’; var events = require(‘events’); var
util = require(‘util’); var EventEmitter = events.EventEmitter; var MyEventEmitter = function(data) { this.data = data; }; util.inherits(MyEventEmitter, EventEmitter); MyEventEmitter.prototype.intervalCheck = function() { var originalData = this.data; var _this = this; setInterval(function (){ if (originalData !== _this.data) { _this.emit(‘change’, new Date() + ‘: ’ + _this.data); originalData = _this.data; } }, 1000); }; module.exports = MyEventEmitter; DIFDLPXOPCKFDUQFSTFD
MyEventEmitter // v4.0 ‘use strict’; const events = require(‘events’); const
EventEmitter = events.EventEmitter; class MyEventEmitter extends EventEmitter { constructor(data) { this.data = data; } intervalCheck() { let originalData = this.data; setInterval(()=>{ if (originalData !== this.data) { this.emit(‘change’, `${new Date()}: ${this.data}`); originalData = this.data; } }, 1000); } } module.exports = MyEventEmitter;
MyEventEmitter // After v4.0 ‘use strict’; const events = require(‘events’);
const EventEmitter = events.EventEmitter; class MyEventEmitter extends EventEmitter { constructor(data) { this.data = data; } intervalCheck() { let originalData = this.data; setInterval(()=>{ if (originalData !== this.data) { this.emit(‘change’, `${new Date()}: ${this.data}`); originalData = this.data; } }, 1000); } } module.exports = MyEventEmitter; SFRVJSF͔ΒDPOTUͰఆٛ͢Δ ෆมͳͱͯ͠มߋ͞Εͳ͍Α͏ʹ͢Δ VUJMJOIFSJUTͷΘΓʹDMBTT FYUFOETΛ͏ BSSPXؔΛ͏ UFNQMBUFTUSJOHMJUFSBMͰจࣈྻ ݁߹Λॻ͘
MyEventEmitter // v0.12 ‘use strict’; var events = require(‘events’); var
util = require(‘util’); var EventEmitter = events.EventEmitter; var MyEventEmitter = function(data) { this.data = data; }; util.inherits(MyEventEmitter, EventEmitter); MyEventEmitter.prototype.intervalCheck = function() { var originalData = this.data; var _this = this; setInterval(function (){ if (originalData !== _this.data) { _this.emit(‘change’, new Date() + ‘: ’ + _this.data); originalData = _this.data; } }, 1000); }; module.exports = MyEventEmitter; // v4.0 ‘use strict’; const events = require(‘events’); const EventEmitter = events.EventEmitter; class MyEventEmitter extends EventEmitter { constructor(data) { this.data = data; } intervalCheck() { let originalData = this.data; setInterval(()=>{ if (originalData !== this.data) { this.emit(‘change’, `${new Date()}: ${this.data}`); originalData = this.data; } }, 1000); } } module.exports = MyEventEmitter; #FGPSF "GUFS ͖ͬ͢Γॻ͚ΔΑ͏ʹͳͬͨɻ
·ͩ • default params • rest/spread (ଟv5.0Ͱenable) • tail call
opts • Proxy • Reflect • modules ((ƅ㱼ƅ)ŋ㲎. ŞƄŰŕ!!)
Strong Script
Strong Script • ES6 ͷίʔυΛڧ੍ͤ͞ΔΈ • “use strong” σΟϨΫςΟϒΛॻ͘ •
node —strong_mode hoge.js Ͱىಈ • var Λ let/constʹม͑ͨΓɺdeleteެจΛ͏ͱౖΒΕͨ Γ͢Δɻ • experimental feature
“use strong” “use strong”; function foo() { // v8 4.2
enabled (io.js v2.0 also) var obj1 = ‘aaa’; // Restrict var (use let or const instead) let args = arguments; // Restrict arguments (use Rest Params …args) if (obj1 == ‘aaa’) {} // Restrict == (use strict equal ===) if (obj1 === ‘aaa’); // Restrict empty if and for for (let n in [1,2,3]) // Restrict for-in (use for-of instead) delete obj1.key // Restrict delete operator (use Map/Set instead) // v8 4.5 enabled TODO: try let undefined = ‘aaa’; // Restrict undefined binding let obj3 = { foo : ‘aaa’}; obj3.bar = ‘123’; // Restrict undefined property access }
DEMO
ৄ͘͠
ESIntl
ESIntl • ECMAScript ࠃࡍԽAPI • ECMA-402 / ௨শ ESIntl •
nodebuildͷ࣌ʹ’--with-intl=full-icu — download-all’Λࢦఆ͢Δͱ৽͘͠built-inΦ ϒδΣΫτͷIntlΦϒδΣΫτ͕༗ޮʹͳΔɻ
ESIntl
ESIntl 4USJOH OVN SFQMBDF aE aEaEaE aE H
DEMO
JavaScript Syntax/Features • ES2015ڧԽ • Strong Script͕࣮ݧతʹೖͬͯΔ • ࠃࡍԽAPI͕buildΦϓγϣϯࢦఆͰೖΕΒΕ ΔΑ͏ʹͳͬͨɻ
API
Buffer
Buffer • Buffer#indexOfϝιου͕Ճ • BufferͷϦϑΝΫλϦϯά͕ਐΈɺ ArrayBufferͰॻ͖͞ΕΔɻ • Bufferͷ܁Γฦ͠ʹfor/ofจ͕͑ΔΑ͏ʹ ͳΔɻ
Bufferࠓੲޠ • ͦͦBuffer v0.1.90Ͱ࣮͞Εͨ • ͦͷ࣌ArrayBufferଘࡏ͠ͳ͔ͬͨ • ్த͔ΒArrayBuffer͕༷Խ͞Ε࣮ͯ͞ΕͨͨΊࣅͨΑ͏ ͳػೳΛ࣋ͭAPI͕Ͱ͖ͯ͠·ͬͨɻ •
v4.0ͷλΠϛϯάͰv8͔ΒϝϞϦΛΞϩέʔτ͢Δؔ ͕deprecatedͱͳΓɺBufferΫϥεArrayBufferΫϥεΛҾ ͖ܧ͙ܗͰ࣮͞Εͨɻ
Buffer#indexOfϝιουͷՃ จࣈྻԽ͔ͯ͠ΒJOEFY0G͢ΔΑΓང͔ʹޮ͕ྑ͍ɻ
Buffer instanceOf ArrayBuffer "SSBZ#V⒎FSΫϥεͷΠϯελϯεΛͦͷ··ͤΔ
Buffer for/of var buf = new Buffer([1, 2, 3]); for
(var b of buf) console.log(b) // 1 // 2 // 3 #V⒎FS͕JUFSBUPSʹʂʂʂ
DEMO
Stream
Stream • Simple Stream Constructor͕Ͱ͖ͨ • StreamΛ࡞Δͷʹthrough2ͱ͔Λ͏ඞཁ ͕ͳ͘ͳͬͨ
Simple Stream Constructor // v0.12 var Transform = require('stream').Transform; var
util = require('util'); util.inherits(MyTransform, Transform); function MyTransform(opts){ Transform.call(this, opts); } MyTransform.prototype._transform = function(chunk, encoding, callback){ // ͜͜Ͱ มͯ͠ ... // push͢Δ this.push(chunk); }; MyTransform.prototype._flush = function(done){ // ࠷ޙʹԿ͔͚ͨ͠Ε͜͜Ͱ flush ͢Δ };
Simple Stream Constructor // v4.0 var transform = new stream.Transform({
transform: function(chunk, encoding, next) { // ͜͜Ͱ มͯ͠ ... // push͢Δ this.push(chunk); }, flush: function(done) { // ࠷ޙʹԿ͔͚ͨ͠Ε͜͜Ͱ flush ͢Δ } }); ؆୯ʂUISPVHIͱಉ͡ॻ͖ํʂʂ
REPL
REPL • historyΛηʔϒͯ͘͠ΕΔΑ͏ʹͳͬͨ • ී௨͚ͩͲɺΊͬͪΌخ͍͠
DEMO
OS
OS • os.homeDir()͕Ճ • ࠓ·ͰhomeσΟϨΫτϦऔΕͳ͔͚ͬͨͲ औΕΔΑ͏ʹͳͬͨ
API • BufferͷϦϑΝΫλϦϯάͱindexOfͷՃ • Stream͕γϯϓϧʹ࡞ΕΔΑ͏ʹͳͬͨ • REPL͕historyΛηʔϒͯ͘͠ΕΔΑ͏ʹͳͬ ͨ • os.homeDir()͕Ճ
Performance
require͕ߴԽ
require͕ߴԽ • ͜Ε·Ͱɺfs.statSyncͱfs.readFileSyncΛ ͕ͬͯͨɺstatSync͍͠ɺ readFileSyncຖճϓϩύςΟݺͼग़ͯ͠͠ Δͱएׯ͔͔࣌ؒΔɻ • ෦తʹߴͳAPI࡞ͬͨΒ50xߴԽ͞Ε ͨɻ
http͕ߴԽ
http͕ߴԽ • http-parser͕ΞοϓάϨʔυ͞ΕɺߴԽ͕ ೖΓɺ͞ΒʹhttpϞδϡʔϧ͕ߴԽ͞Εͨ
http͕ߴԽ • ϝϞϦར༻վળ
Performance • require͕50xߴԽ • http͕8%վળ • ϝϞϦޮΞοϓ
Deprecated
೦ͳ͕Βdeprecatedʹͳͬ ͨAPIୡ
domains
domainsΤϥʔΩϟον ग़དྷ͔ͯͦͬΒग़དྷΔ͜ͱ ͕গͳ͍ΑͶ… => deprecated
fs.exist/existSync
fs.existͰଘࡏ֬ೝͰ͖Δ͚ Ͳɺଘࡏ֬ೝͨ͠ޙʹผͳϓ ϩηε͔Βফ͞ΕͨΒͲ͏͢ Μͷʁ => deprecated
util.isXXXX
util.isXXX ͢ͱ͍
util.isObject ͕ functionΛ ObjectͱΈͳͯ͠ͳ͍ underscore/lodashͪΌΜ ͱ_.isObjectͰtrueʹͳΔ
࣮JSͷ༷తʹFunction ObjectͷҰͭ
मਖ਼͢Δͱmajor্͕ͬͪΌ ͏…
ͦͦཁΒͳ͘Ͷʁ => deprecated
Deprecated • domains • fs.exists • util.isXXXXX
Conclusion
Conclusion • ES.nextػೳڧԽ • API͕एׯύϫʔΞοϓ • ੑೳվળʂʂʂ • deprecatedͳAPIࠓޙΘͳ͍Α͏ ʹʂʂʂʂ