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.3k
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.5k
Other Decks in Programming
See All in Programming
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
260
快速入門可觀測性
blueswen
0
370
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
330
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
810
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
780
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
450
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Designing for Performance
lara
604
68k
Fireside Chat
paigeccino
34
3.1k
Automating Front-end Workflow
addyosmani
1366
200k
Producing Creativity
orderedlist
PRO
341
39k
YesSQL, Process and Tooling at Scale
rocio
169
14k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
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ࠓޙΘͳ͍Α͏ ʹʂʂʂʂ