How I learned
to stop worrying
and love the browser
as a gaming platform.
About me
Jay Oster <jay@kodewerx.org>
@kodewerx
|
|
HTML5 Games? Really?
melonJS: A lightweight HTML5 game engine
Demo time!
Squeeze the life out of JavaScript
V8 Hidden Classes
function Point(x, y) {
this.x = x;
this.y = y;
}
var point = new Point(10, 20);
point.z = 15;
V8 Hidden Classes
function Point(x, y) {
this.x = x; // Change the hidden class
this.y = y; // Change the hidden class (again)
}
var point = new Point(10, 20);
point.z = 15; // Don’t do this
Use ES6 Classes (Chrome 42+)
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color;
}
}
No ES6 Classes? Prototype Chain!
function Point(x, y) {
this.x = x;
this.y = y;
}
function ColorPoint(x, y, color) {
Point.prototype.call(this, x, y); // super
this.color = color;
}
Use ES6 Maps (Chrome 38+)
var m = new Map([
[ null, "foo" ],
[ function () {}, "bar" ]
]);
m.has(null); //> true
m.get(null); //> "foo"
m.has(function () {}); //> false
m.get(10); //> undefined
HTML5 Desktop Hosts
HTML Mobile Hosts
Demo Time!
Jay Oster <jay@kodewerx.org>
@kodewerx
https://github.com/parasyte/jay-inheritance
https://github.com/atom/electron