Javascrpt arale5. web 术 职责
JavaScript语
选择 DOM
6. web 术 职责
JavaScript语
选择 DOM
Arale
10. 职责 MVC
HTML M
CSS 样 V
JavaScript 为 C
11. 职责 MVC
HTML M
CSS 样 V
JavaScript 为 C
12. 职责 MVC
HTML M
CSS 样 V
JavaScript 为 C
13. web 术 职责
JavaScript语
选择 DOM
Arale
17. 语
变 时
number, string,
object, boolean, null, undefined
18. 语
变 时
number, string,
object, boolean, null, undefined
28. var x = new Boolean(false);
if (x) {
alert('hi'); // Shows 'hi'.
}
29. var x = new Boolean(false);
if (x) {
alert('hi'); // Shows 'hi'.
}
var x = Boolean(0);
if (x) {
alert('hi'); // This will never be alerted.
}
typeof Boolean(0) == 'boolean';
typeof new Boolean(0) == 'object';
31. function f1(x) {
var a = 1;
if(x) {
var b = 2;
}
function f2() {
var c = 3;
}
console.log(a);
console.log(b);
console.log(c);
}
f1(4);
32. function f1(x) {
var a = 1; 1
if(x) { 2
var b = 2; undefined
}
function f2() {
var c = 3;
}
console.log(a);
console.log(b);
console.log(c);
}
f1(4);
37. if (x) { if (x) {
function foo() {} var foo = function() {}
} }
39. expression & literal
function fn() {
console.log(f1);
var f1 = function() {
console.log("f1")
}
console.log(f1);
console.log(f2);
function f2() {
}
console.log(f2);
var f2 = function() {
console.log("f3");
}
f2();
}
fn()
40. expression & literal
function fn() {
console.log(f1);
var f1 = function() {
console.log("f1")
}
console.log(f1);
console.log(f2);
function f2() {
}
console.log(f2);
var f2 = function() {
console.log("f3");
}
f2();
}
fn()
41. expression & literal
function fn() {
console.log(f1);
var f1 = function() {
console.log("f1") 结
}
console.log(f1); null
function
console.log(f2);
function f2() { function
} function
console.log(f2);
f3
var f2 = function() {
console.log("f3");
}
f2();
}
fn()
50. 对 prototype
function Circle(x, y, z) {
this.x = x;
this.y = y;
this.r = r;
this.getR = function() { return this.r;};
}
//instance method
Circle.prototype.area = function() {
return this.r * this.r * 3.14159;
}
var c = new Circle(0, 0, 2);
alert(c.area());
51. 对 prototype
function Circle(x, y, z) {
this.x = x;
this.y = y; getR Vs. area
this.r = r;
this.getR = function() { return this.r;};
}
//instance method
Circle.prototype.area = function() {
return this.r * this.r * 3.14159;
}
var c = new Circle(0, 0, 2);
alert(c.area());
52. 对 prototype
function Circle(x, y, z) {
this.x = x;
this.y = y; getR Vs. area
this.r = r;
this.getR = function() { return this.r;};
}
//instance method
Circle.prototype.area = function() {
//static method
return this.r * this.r * 3.14159;
Circle.getClassName = function() {
}
return “Circle”;
var c = new Circle(0, 0, 2);
}
alert(c.area());
53. 对 prototype
function Circle(x, y, z) {
this.x = x;
this.y = y; getR Vs. area
this.r = r;
this.getR = function() { return this.r;};
}
//instance method
Circle.prototype.area = function() {
//static method
return this.r * this.r * 3.14159;
Circle.getClassName = function() {
}
return “Circle”;
var c = new Circle(0, 0, 2);
}
alert(c.area());
prototype 对 实 对 这 为 础
55. 继
function ClassA(sColor) {
this.color = sColor;
}
ClassA.prototype.sayColor = function () {
alert(this.color);
};
function ClassB(sColor, sName) {
ClassA.call(this, sColor);
this.name = sName;
}
ClassB.prototype = new ClassA();
ClassB.prototype.sayName = function () {
alert(this.name);
};
56. 继
function ClassA(sColor) {
this.color = sColor;
}
ClassA.prototype.sayColor = function () {
};
alert(this.color);
对
function ClassB(sColor, sName) {
ClassA.call(this, sColor);
this.name = sName;
}
ClassB.prototype = new ClassA();
ClassB.prototype.sayName = function () {
alert(this.name);
};
57. 继
function ClassA(sColor) {
this.color = sColor;
}
ClassA.prototype.sayColor = function () {
};
alert(this.color);
对
function ClassB(sColor, sName) {
ClassA.call(this, sColor);
this.name = sName;
}
ClassB.prototype = new ClassA();
链
ClassB.prototype.sayName = function () {
alert(this.name);
};
58. 继
function ClassA(sColor) {
this.color = sColor;
}
ClassA.prototype.sayColor = function () {
};
alert(this.color);
对
function ClassB(sColor, sName) {
ClassA.call(this, sColor);
this.name = sName;
}
ClassB.prototype = new ClassA();
链
ClassB.prototype.sayName = function () {
alert(this.name);
};
59. 继 对 + 链
function ClassA(sColor) {
this.color = sColor;
}
ClassA.prototype.sayColor = function () {
alert(this.color);
};
function ClassB(sColor, sName) {
ClassA.call(this, sColor);
this.name = sName;
}
ClassB.prototype = new ClassA();
ClassB.prototype.sayName = function () {
alert(this.name);
};
62. 闭
编 严
调
闭 给
变 环
变
scope chain
63. 闭 var sMessage = "hello world";
function sayHelloWorld() {
alert(sMessage);
编 严
}
调 sayHelloWorld();
闭 给
变 环
变
scope chain
64. 闭 var sMessage = "hello world";
function sayHelloWorld() {
alert(sMessage);
编 严
}
调 sayHelloWorld();
var iBaseNum = 10;
闭 给
function addNum(iNum1, iNum2) {
function doAdd() {
变 环
return iNum1 + iNum2 + iBaseNum;
变 }
return doAdd();
scope chain }
65. 闭 var sMessage = "hello world";
function sayHelloWorld() {
alert(sMessage);
编 严
}
调 sayHelloWorld();
var iBaseNum = 10;
闭 给
function addNum(iNum1, iNum2) {
function doAdd() {
变 环
return iNum1 + iNum2 + iBaseNum;
变 }
return doAdd();
scope chain }
简单 说 闭
义 变
69. 驱动 编
<button id=”btn” onclick=”alert(‘button clicked!’);”>Click Me!</button>
70. 驱动 编
<button id=”btn” onclick=”alert(‘button clicked!’);”>Click Me!</button>
var btn = document.getElementById(‘btn’);
btn.onclick = function() {
alert(“button clicked”);
}
71. 驱动 编
<button id=”btn” onclick=”alert(‘button clicked!’);”>Click Me!</button>
var btn = document.getElementById(‘btn’);
btn.onclick = function() {
alert(“button clicked”);
}
var btn = document.getElementById(‘btn’);
if(window.addEventListener) {
btn.addEventListener(‘click’, function() {alert(1);}, false);
} else {
btn.attachEvent(‘onclick’, function() {alert(1);});
}
72. 驱动 编
<button id=”btn” onclick=”alert(‘button clicked!’);”>Click Me!</button>
var btn = document.getElementById(‘btn’);
btn.onclick = function() {
alert(“button clicked”);
}
var btn = document.getElementById(‘btn’);
if(window.addEventListener) {
btn.addEventListener(‘click’, function() {alert(1);}, false);
} else {
btn.attachEvent(‘onclick’, function() {alert(1);});
}
74. click submit
change keydown
load keypress
mouseover resize
mouseout scroll
blur ......
75. web 术 职责
JavaScript语
选择 DOM
Arale
87. DOM
getElementById removeChild
firstChild, lastChild,childNodes replaceChild
previousSibling, nextSibling,
createElement
parentNode
getElementsByTagNam createTextNode
e
insertBefore
appendChild
innerHTML
88. var newP = document.createElement("p");
var txt = 'Kilroy was here.';
var newT = document.createTextNode(txt);
newP.appendChild(newT);
var p2 = document.getElementsByTagName('p')[1];
p2.parentNode.replaceChild(newP,p2);
90. 选择 /selector
css选择
sizzle
91. web 术 职责
JavaScript语
选择 DOM
Arale
100. Alice
Arale Js maven
Arale
static server
combo
101. Alice
Arale Js maven
Arale
static server
combo
104. Hello World!
$E.domReady(function(){
$("btn").click(function(e){
alert("Hello Arale!");
});
});
108. Selector
id选择 : $(‘id’)
Node
杂选择 $$(selector)
109. Selector
id选择 : $(‘id’)
Node
杂选择 $$(selector)
组 组 节 为Node
111. Dom & Node
$D —— 态
$Node—— 对 获 实
Dom
toDom
getPosition
setStyle
getDocumentWidth
getDocumentHeight
getViewportWidth
getViewportHeight
112. Dom & Node
$D —— 态
$Node—— 对 获 实
Node
Dom
addClass
toDom removeClass
getPosition attr
setStyle inject
getDocumentWidth getStyle
getDocumentHeight setStyle
getViewportWidth next
getViewportHeight previous
parent
query
114. Event——$E
$E.domReady(function() {
//do something
});
115. Event——$E
connect
disconnect
$E.domReady(function() {
//do something subscribe
});
unsubscribe
publish
trigger
delegate
live
116. Event——$E
connect
disconnect
$E.domReady(function() {
//do something subscribe
});
unsubscribe
publish
trigger
delegate
live
126. 颗 块设计 combo 务
Loader.use(‘arale.http’, function() {
$Ajax.get(‘url’, {
success: function() {
}
});
});
127. A B
Loader.use(‘C’, function() {
//some code here
})
C
载C 块js 时
A B还 载 时
载
128. 颗 块设计
A B
Loader.use(‘C’, function() {
//some code here
})
C
载C 块js 时
A B还 载 时
载
137. 码检
压缩
测试
编码检测 Maven
赖 计
138. 项
码检
压缩
测试
编码检测 Maven
赖 计
140. task
JS实现
Array#sort
(delegate)
Arale demo