Upgrade to Pro — share decks privately, control downloads, hide ads and more …

io.js 東京Node学園 15時限目

io.js 東京Node学園 15時限目

io.js 東京Node学園の15時限目の資料です。

Yosuke Furukawa

February 10, 2015
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. "use strict"; // const const koa = require('koa'); const app

    = koa(); // generator app.use(function *(next){ // let block scope let start = new Date; // yield ඇಉظݺͼग़͠ΛݮΒͤΔ yield next; let ms = new Date - start; // template string literal this.set('X-Response-Time', `${ms}ms`); }); app.use(function *(next){ let start = new Date; yield next; let ms = new Date - start; console.log(`{this.method} {this.url} - ms`); }); ͜Μͳ෩ʹॻ͚Δ
  2. "use strict"; // class class Person { constructor(name, age) {

    this.name = name this.age = age } getInfo() { let name = this.name; let age = this.age; let nextAge = this.age + 1; // enhanced object literal return { name, age, nextAge }; } } // @@toStringTag ෇͚ͳ͍ͱ [object object] Person.prototype[Symbol.toStringTag] = "Person"; var alice = new Person('alice', 13); var bob = new Person('bob', 15); console.log('' + alice); console.log(bob.getInfo()); ͜Μͳ෩ʹॻ͚Δ
  3. "use strict"; const v8 = require('v8'); // gcΛtrace͢ΔΦϓγϣϯΛONʹ͢Δ v8.setFlagsFromString('--trace-gc'); for

    (let i=0; i< 10000; i++) { // ώʔϓͷ౷ܭΛऔΔ console.log(v8.getHeapStatistics()); global.gc(); } // 10ඵ͚ؒͩv8ͷGCΛtrace͠ɺ͕࣌ؒա͗ͨΒOFFʹ͢Δ setTimeout(function(){ v8.setFlagsFromString('--notrace-gc'); }, 10 * 1000);