constructor is a function
This commit is contained in:
		
							
								
								
									
										21
									
								
								4.5constructor/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								4.5constructor/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="t3.js"></script> | ||||||
|  |  | ||||||
|  |   <!-- the element with id="mocha" will contain test results --> | ||||||
|  |  | ||||||
|  |   <!-- run tests! --> | ||||||
|  | </body> | ||||||
|  |  | ||||||
|  | </html> | ||||||
							
								
								
									
										12
									
								
								4.5constructor/t2.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								4.5constructor/t2.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | function Calculator(){ | ||||||
|  |     this.read = function(){ | ||||||
|  |         this.a = +prompt('a?', 0); | ||||||
|  |         this.b = +prompt('b?', 0); | ||||||
|  |     }; | ||||||
|  |     this.sum = function(){ | ||||||
|  |         return this.a + this.b; | ||||||
|  |     }; | ||||||
|  |     this.mul = function(){ | ||||||
|  |         return this.a * this.b; | ||||||
|  |     }; | ||||||
|  | } | ||||||
							
								
								
									
										11
									
								
								4.5constructor/t3.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								4.5constructor/t3.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | function Accumulator(startingValue){ | ||||||
|  |     this.value = startingValue; | ||||||
|  |     this.read = function(){ | ||||||
|  |         new_value = +prompt("value?", 0); | ||||||
|  |         this.value += new_value; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | let accumulator = new Accumulator(1); | ||||||
|  | accumulator.read(); | ||||||
|  | alert(accumulator.value); | ||||||
		Reference in New Issue
	
	Block a user