The Web As Platform
Past, Present, and Future
Alex Russell <slightlyoff@google.com>
Twitter: @slightlylate
March 27, 2012
Alex Russell <slightlyoff@google.com>
Twitter: @slightlylate
March 27, 2012
flickr.com/photos/stuckincustoms/3145980733
http://infrequently.org:8080/
...you are technically correct — the BEST kind of correct.
flickr.com/photos/arnolouise/364315704
flickr.com/photos/11304375@N07/2252583074/
flickr.com/photos/kadenis/5121129043/
<a>
flickr.com/photos/donsolo/3271552182/
// Classes are state with functions
function Behavior(config) {
this.config = config;
this.doIt = function(itemToActOn) {
if (this.config.flag) {
// ...
} else {
// ...
}
}
}
var b = new Behavior({ flag: false });
b.doIt($("item"));
// Closures are functions with state
function bindBehavior(config) {
return function() {
if (config.flag) {
// ...
} else {
// ...
}
}
}
var b = bindBehavior({ flag: false });
b($("item"));
flickr.com/photos/evanblaser/5573908825
HTTPArchive, 2012
flickr.com/photos/imh/3297961043/
Throughout history
Every mystery
Ever solved has turned out to be
Not Magic.
<script
src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js">
</script>
<script>
dojo.require("dijit.dijit");
dojo.require("dijit.Calendar");
dojo.ready(function() {
var c = new dijit.Calendar({
value: new Date(),
isDisabledDate: function(d) {
// ...
}
});
document.body.appendChild(c.domNode);
});
</script>
function Comment(text) {
HTMLElement.call(this); // Makes this an Element
this.textContent = text || '...';
this.buildUI();
}
Comment.prototype = Object.create(HTMLElement.prototype);
Comment.prototype.constructor = Comment;
Comment.prototype.buildUI = function() { ... };
HTMLElement.register('x-comment', Comment);
var c = new Comment("Howdy, pardner!");
document.body.appendChild(c);
<!-- At risk in standards --> <x-comment>...</x-comment> <!-- Might instead be: --> <div is="x-comment">...</div>
function Comment(text) {
HTMLElement.call(this); // Makes this an Element
this.textContent = text || '...';
this.shadow = new ShadowRoot(this);
this.buildUI();
}
Comment.prototype = Object.create(HTMLElement.prototype);
Comment.prototype.constructor = Comment;
Comment.prototype.buildUI = function() { ... };
HTMLElement.register('x-comment', Comment);
<element extends="div" name="greeting" constructor="Howdy">
<script>
this.lifecycle({
created: function(shadowRoot) {
shadowRoot.shadowHost.addEventHandler("click", function() {
alert("And good day to you!");
});
}
});
</script>
<template><h1>Hello World!</h1></template>
</element>
<div is="greeting"></div>
var c = new Greeting(); document.body.appendChild(c);
<script>
document.body.model = Model.get({
'items': [
{ 'name': 'Africa',
'children': [
{ 'name': 'Egypt' },
{ 'name': 'Kenya',
'children': [ { 'name': 'Nairobi' }, { 'name': 'Mombasa' } ]
} ] } ]
});
</script>
<template iterate="items" id="t">
<li>{{name}}
<ul><template ref="t" iterate="children"></template></ul>
</li>
</template>
<script>
var summary = new MutationSummary({
callback: [function], // required
rootNode: [node], // optional
observeOwnChanges: [boolean], // optional
queries: [{query}, …] // required. one query object at min.
});
// ...sometime later
summary.disconnect();
</script>
http://infrequently.org:8080/module widgets {
module events from 'goog/events.js';
import {EventType, FocusHandler, KeyHandler} from events;
import * from 'goog/widget.js';
export let collection = new WeakMap();
export class DropDownButton extends Widget {
constructor(attributes) {
super(attributes);
this.buildUI();
// ...
}
}
}
const Point2D = new StructType({ x: uint32, y: uint32 });
const Color = new StructType({ r: uint8, g: uint8, b: uint8 });
const Pixel = new StructType({ point: Point2D, color: Color });
const Triangle = new ArrayType(Pixel, 3);
let t = new Triangle([{ point: { x: 0, y: 0 },
color: { r: 255, g: 255, b: 255 } },
{ point: { x: 5, y: 5 },
color: { r: 128, g: 0, b: 0 } },
{ point: { x: 10, y: 0 },
color: { r: 0, g: 0, b: 128 } }]);
let someObject = { name: "yet another anonymous object" };
let collection = new WeakMap();
collection.set(someObject, anotherObject);
collection.has(someObject) == true;
collection.get(someObject); // anotherObject
for (let [key, val] of items(someObject)) {
// Look ma! I'm bound per iteration!
doWork(val);
}
function Comment(text) {
HTMLElement.call(this); // Makes this an Element
...
}
Comment.prototype = Object.create(HTMLElement.prototype);
Comment.prototype.constructor = Comment;
Comment.prototype.buildUI = function() { ... };
HTMLElement.register('x-comment', Comment);
// Closure
goog.inherits(HTMLElement, Comment);
// Prototype
Comment = Class.create(HTMLElement, ... );
// MooTools
Comment = new Class({ extends: HTMLElement, ... });
// YUI
Comment = function () { Comment.superclass.constructor.call(this); };
YAHOO.lang.extend(Comment, HTMLElement);
// Dojo
dojo.define("Comment", [ HTMLElement ], ...);
// jQuery UI
$.widget( "comment", { ... });
class Comment extends HTMLElement {
constructor(attrs = {}, ...args) {
super(attrs);
this.textContent = attrs.text || lorem;
this.shadow = new ShadowRoot(this);
this.buildUI(...args);
}
buildUI() { /*...*/ }
css(...args) {
super.css(...args);
// Custom work here
}
}