Browse Source

Default Changelist

master
DeW 1 year ago
commit
5e03e90583
  1. 2
      .gitignore
  2. 103
      README.md
  3. 32
      chapter1/chapter1.1/javascript_conditional_branching.js
  4. 25
      chapter1/chapter1.1/javascript_objects.js
  5. 25
      chapter1/chapter1.1/javascript_operators.js
  6. 28
      chapter1/chapter1.1/javascript_statements.js
  7. 15
      chapter1/chapter1.1/javascript_this.js
  8. 13
      chapter1/chapter1.1/javascript_types.js
  9. 14
      chapter1/chapter1.2/client_javascript.html
  10. 14
      chapter1/chapter1.2/debug.js
  11. 15
      chapter1/chapter1.2/hide_debug.html
  12. 12
      chapter1/chapter1.2/hide_element.js
  13. 6
      chapter1/chapter1.2/javascript_function.js
  14. 11
      tips/test.html
  15. 4
      tips/var_let.js

2
.gitignore

@ -0,0 +1,2 @@
/.git/
/.idea/

103
README.md

@ -0,0 +1,103 @@
##### 书名:JavaScript权威指南(第6版) 作者:[美]\(Flanagan, D)
| INDEX | FILE_PATH | COMMIT |
| ----- | ---------------------------------------------- | ------------------ |
| 1 | chapter1.1/javascript_types.js | #types |
| 2 | chapter1.1/javascript_objects.js | #objects |
| 3 | chapter1.1/javascript_operators.js | #operators |
| 4 | chapter1.1/javascript_statements.js | #statements |
| 5 | chapter1.1/javascript_conditional_branching.js | #condi_branch |
| 6 | chapter1.1/javascript_this.js | #this |
| 7 | chapter1.2/debug_hide.html | #debut_hide_button |
| 8 | chapter1.2/javascript_function.js | #function |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |

32
chapter1/chapter1.1/javascript_conditional_branching.js

@ -0,0 +1,32 @@
var x = 2
function abs(x) {
if (x >= 3) {
return x;
} else {
return -x;
}
}
console.log(abs(x))
function factorial(n) {
var product = 1;
while (n > 1) {
product *= n;
n--;
}
return product;
}
console.log(factorial(4))
function factorial2(n) {
var i, product = 1;
for (i = 2; i <= n; i++) {
product *= i;
}
return product;
}
console.log(factorial2(5))

25
chapter1/chapter1.1/javascript_objects.js

@ -0,0 +1,25 @@
let book = {
topic: "JavaScript",
fat: true,
};
console.log(book.topic)
console.log(book.fat)
book.author = "Flanagan";
book.contents = {};
let primes = [2, 3, 5, 7];
console.log(primes[0])
console.log(primes.length)
console.log(primes[primes.length - 1])
console.log(primes[4])
primes[4] = 11;
console.log(primes[4])
let empty = []
console.log(empty.length)
var points = [
{x: 0, y: 0},
{x: 1, y: 1},
];
var data = {
trial1: [[1, 2], [3, 4]],
trail2: [[5, 6], [7, 8]],
};

25
chapter1/chapter1.1/javascript_operators.js

@ -0,0 +1,25 @@
console.log(3 + 2) //5
console.log(3 - 2) //1
console.log(3 * 2) //6
console.log(3 / 2) //1.5
let points = [{x: 1}, {x: 2}];
console.log(points[1].x - points[0].x) //1
console.log("3" + "2"); //32
let count = 0;
console.log(count++) //0
console.log(count--) //1
console.log(count += 2) //2
console.log(count *= 3) //3
let x = 2, y = 3;
console.log(x == y) //false
console.log(x != y) //true
console.log(x < y) //true
console.log(x <= y) //true
console.log(x > y)
console.log(x >= y)
console.log("two" == "three")
console.log("two" > "three")
console.log(false == (x > y))
console.log((x == 2) && (y == 3)) //true
console.log((x > 3) || (y < 3));
console.log(!(x == y)) //false

28
chapter1/chapter1.1/javascript_statements.js

@ -0,0 +1,28 @@
var x = 2, y = 3;
function plus1(x) {
return x + 1;
};
console.log(plus1(x))
var square = function (x) {
return x * x;
};
console.log(square(plus1(y)))
var a = [];
a.push(1, 2, 3)
console.log(a)
a.reverse();
console.log(a)
var points = [
{x: 0, y: 0},
{x: 1, y: 1},
];
points.dist = function () {
var p1 = this[0];
var p2 = this[1];
var a = p2.x - p1.x
var b = p2.y - p1.y;
return Math.sqrt(a * a + b * b);
}
console.log(points.dist())

15
chapter1/chapter1.1/javascript_this.js

@ -0,0 +1,15 @@
function Point(x, y) {
this.x = x;
this.y = y;
// list = [];
// list.push(this.x, this.y)
// return list;
}
// console.log(Point(1, 2))
var p = new Point(1, 1);
Point.prototype.r = function () {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
console.log(p.r())

13
chapter1/chapter1.1/javascript_types.js

@ -0,0 +1,13 @@
let x;
x = 0;
console.log(x);
x = 1;
console.log(x);
x = 0.01;
console.log(x);
x = "hello world";
x = "JavaScript";
x = true;
x = false;
x = null;
x = undefined;

14
chapter1/chapter1.2/client_javascript.html

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Client_JavaScript</title>
<script src="library.js"></script>
</head>
<body>
<p>This is a paragraph of HTML.</p>
<script>
<p>Here is more HTML.</p>
</script>
</body>
</html>

14
chapter1/chapter1.2/debug.js

@ -0,0 +1,14 @@
function debug(msg) {
var log = document.getElementById("debuglog");
if (!log) {
log = document.createElement("div");
log.id = "debuglog";
log.innerHTML = "<h1>Debug Log</h1>";
document.body.appendChild(log);
}
var pre = document.createElement("pre");
var text = document.createTextNode(msg);
pre.appendChild(text);
log.appendChild(pre);
}

15
chapter1/chapter1.2/hide_debug.html

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hide_Debug</title>
<script src="debug.js"></script>
<script src="hide_element.js"></script>
</head>
<body>
Hello,
<button onclick="hide(this,true);debug('hide button 1');">Hide1</button>
<button onclick="hide(this); debug('hide button 2');">Hide2</button>
World!
</body>
</html>

12
chapter1/chapter1.2/hide_element.js

@ -0,0 +1,12 @@
function hide(e, reflow) {
if (reflow) {
e.style.display = "none"
} else {
e.style.visibility = "hidden";
}
}
function highlight(e) {
if (!e.className) e.className = "hilite";
else e.className += "hilite";
}

6
chapter1/chapter1.2/javascript_function.js

@ -0,0 +1,6 @@
function moveon() {
var answer = confirm("Ready?")
if (answer) window.location = "http://taobao.com";
}
setTimeout(moveon, 60000)

11
tips/test.html

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test_html</title>
<script src="var_let.js"></script>
</head>
<body>
</body>
</html>

4
tips/var_let.js

@ -0,0 +1,4 @@
var a = 1
console.log(window.a) //1
let b = 2
console.log(window.b) //undefined
Loading…
Cancel
Save