forked from WebProgrammingII/WEPO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects_example.js
51 lines (27 loc) · 1.45 KB
/
objects_example.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
/**
* Demonstration on how to create, update and manipulate objects
*/
/* Part I - Working with the object */
// 1. Declare an object using object literals, with both stringed props and not
// 2. Change properties using [] and dot notation
// 3. Add a property dynamically
// 4. Pass the object to a function which adds a property and console.log afterwards
// 5. Object.getOwnPropertyDescriptor()
// 6. Delete a property from the object literal object
// 7. Set the defineProperty as non-configurable
// 8. Try to delete another property
// 8.1. Define a getter for the User for fullName
// 8.2. Define a setter for the User for fullName
/* Part II - Object-oriented JS */
// 9. Create a constructor function for Bug(), which takes in name, age
// 10. Define makeSound()
// 10.1. Define die()
// 11. Create a constructor function for Cockroach(), which takes in name, age and if age is more than 1 canFly = true
// 12. Assign the prototype to Bug and constructor to Cockroach
// 13. Define a method for Cockroach called makeSound()
// 14. Create an object of Cockroach()
// 15. Loop through it and use both the in operator and hasOwnProperty()
// 16. Create a constructor function for Ant(), which takes in name and age
// 17. Make Ant inherit from Bug
// 18. For a new instance of Ant call makeSound
// 19. Extend Array.prototype with a function called evenElements()