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
140
Removing Corepack
yosuke_furukawa
PRO
9
1.2k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.4k
Strip Types と Storage
yosuke_furukawa
PRO
4
330
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.1k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
690
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.2k
リアーキテクトと開発生産性について
yosuke_furukawa
PRO
25
9.5k
Other Decks in Programming
See All in Programming
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
830
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
EventSourcingの理想と現実
wenas
6
2.1k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
100
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
150
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
430
役立つログに取り組もう
irof
26
8.6k
Featured
See All Featured
For a Future-Friendly Web
brad_frost
175
9.4k
Thoughts on Productivity
jonyablonski
67
4.3k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Six Lessons from altMBA
skipperchong
26
3.5k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Practical Orchestrator
shlominoach
186
10k
Code Review Best Practice
trishagee
64
17k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Designing for humans not robots
tammielis
249
25k
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ࠓޙΘͳ͍Α͏ ʹʂʂʂʂ