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
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
1
3.2k
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
170
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
350
Module Harmony について
yosuke_furukawa
PRO
3
1.6k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
720
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.4k
Other Decks in Programming
See All in Programming
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
Go の GC の不得意な部分を克服したい
taiyow
2
770
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
fs2-io を試してたらバグを見つけて直した話
chencmd
0
220
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
return文におけるstd::moveについて
onihusube
1
920
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
useSyncExternalStoreを使いまくる
ssssota
6
1k
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
A Tale of Four Properties
chriscoyier
157
23k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Adopting Sorbet at Scale
ufuk
73
9.1k
GitHub's CSS Performance
jonrohan
1030
460k
Writing Fast Ruby
sferik
628
61k
Building Adaptive Systems
keathley
38
2.3k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
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ࠓޙΘͳ͍Α͏ ʹʂʂʂʂ