SCIVONE Tech Talks #0 マルチデバイス対応を踏まえたフロントエンド開発事情
JavaScript の特徴を活かそう
1
DOM Wrapper
HTML System
HTML System
Tag Element
<canvas id=”c1”>
<style id=”s1”>
c1 = document.getElementById('c1');
context = c1.getContext('2d');
context.draw(..);
s1 = document.getElementById('s1');
sheet = s1.sheet;
sheet.rules.insertRule(...);
Tag Element
Context Object
Context
Object
SCIVONE Tech Talks #0 マルチデバイス対応を踏まえたフロントエンド開発事情
JavaScript の特徴を活かそう
keys
2
hash
function
hashes
00
Hash Map
John Smith
01
02
Lisa Smith
Sam Doe
03
04
自由に Key 、 Value の追加削除ができる
00
var temp = {};
temp.newKey = 3;
delete temp.newKey;
JavaScript 内のすべてのオブジェクトは HashMap
オブジェクトではないもの: Primitive
参照されずにコピーされる
string, number, boolean, NaN, undefined, null
var temp = function(){};
temp.a =3;
temp = new Date;
temp.b = 3;
temp = [3,4,5];
temp.c = 3
http://en.wikipedia.org/wiki/Hash_table
SCIVONE Tech Talks #0 マルチデバイス対応を踏まえたフロントエンド開発事情
JavaScript の特徴を活かそう
3
Prototype
クラスがない
共有リソース(メソッド、フィールド)を保管する場所がない
関数の特定のキーを共有するリソースのアーカイブに使用
var temp = function(){};
temp.prototype = {};
prototype keyChain
new でオブジェクトを作成すると、指定された関数の prototype を共有する
var func = function(){};
func.prototype = {
test:function(){}
}
var a = {};
a.__proto__ = func.prototype;
var temp= func.apply( a, arguments );
if( typeof temp == 'object' ) a = temp;
var a = new func;
a.test();
a['test'] == undefined a.__proto__.test == func.prototype.test
SCIVONE Tech Talks #0 マルチデバイス対応を踏まえたフロントエンド開発事情
JavaScript の特徴を活かそう
4
Scope
Parent ― 環境関数の EC
function test( a, b ){
var c, d;
}
function global(){
function test( a, b ){
var c, d;
}
}
global();
EC : Execution Context (実行コンテキスト)
function environmentalFunction(){
function concreateFunction(){
}
concreateFunction.scope.parent = environmentalFunction_EC1;
}
environmentalFunction();
environmentalFunction_EC1 = {...};