-
Notifications
You must be signed in to change notification settings - Fork 2
/
NotesDay4.js
67 lines (49 loc) · 1.2 KB
/
NotesDay4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ARGUMENTS creates a list of arguments
function yell() {
console.log(arguments); // Hola Chau
console.log([].slice); // [Function slice]
var args = [].slice.call(arguments, 0);
console.log(args);
}
yell('Hola', 'Chau');
// CLOSURE: function that returns a function
function createService() {
var secretKey = 'hulala';
function service() {
console.log(secretKey + 'is secret');
}
return service;
}
var ser = createService();
ser(); //
function createBall() {
var speed = [4,4];
var Ball = function() {
this.position = [1, 1];
}
Ball.prototype.accelerate = function() {
speed[0] += 1;
spped[1] += 1;
}
Ball.prototype.move = function() {
this.position[0] += 4;
this.position[1] += 4;
}
}
createBall();
// KEYS PRESSED
function oneKeyPressed(e) {
console.log(e.key);
if (e.key === 'a') {
console.log('left');
} else if (e.key === 'd') {
console.log('right');
}
}
document.addEventListener('keypress', oneKeyPress);
// // this is the listener
// document.addEventListener("keydown", keyDownHandler, false);
// document.addEventListener("keyup", keyUpHandler, false);
// document.addEventListener('keydown', function(event) {
// console.log('you pressed a key!');
// });