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
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Better Code Design in PHP
afilina
PRO
0
130
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
最新TCAキャッチアップ
0si43
0
190
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Quine, Polyglot, 良いコード
qnighy
4
650
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
Featured
See All Featured
Side Projects
sachag
452
42k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Optimizing for Happiness
mojombo
376
70k
Designing for Performance
lara
604
68k
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Invisible Side of Design
smashingmag
298
50k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Happy Clients
brianwarren
98
6.7k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
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ࠓޙΘͳ͍Α͏ ʹʂʂʂʂ