learn this, but not very clear
This commit is contained in:
parent
e9d6b3ad15
commit
1e55406e8f
21
4.4this/index.html
Normal file
21
4.4this/index.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- add mocha css, to show results -->
|
||||||
|
<script>
|
||||||
|
// chai has a lot of stuff, let's make assert global
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- the script with tests (describe, it...) -->
|
||||||
|
<!-- <script src="t1.js"></script> -->
|
||||||
|
<script src="t2.js"></script>
|
||||||
|
|
||||||
|
<!-- the element with id="mocha" will contain test results -->
|
||||||
|
|
||||||
|
<!-- run tests! -->
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
18
4.4this/t1.js
Normal file
18
4.4this/t1.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
let calculator={
|
||||||
|
a: 0,
|
||||||
|
b: 0,
|
||||||
|
read(){
|
||||||
|
this.a = prompt("please type a");
|
||||||
|
this.b = prompt("please type b");
|
||||||
|
},
|
||||||
|
sum(){
|
||||||
|
return Number(this.a) + Number(this.b);
|
||||||
|
},
|
||||||
|
mul(){
|
||||||
|
return this.a * this.b;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
calculator.read();
|
||||||
|
alert(calculator.sum());
|
||||||
|
alert(calculator.mul());
|
16
4.4this/t2.js
Normal file
16
4.4this/t2.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
let ladder = {
|
||||||
|
step: 0,
|
||||||
|
up() {
|
||||||
|
this.step++;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
down() {
|
||||||
|
this.step--;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
showStep: function() { // shows the current step
|
||||||
|
alert( this.step );
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
|
Loading…
Reference in New Issue
Block a user