Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. JavaScript Object
  2. //////////
  3. let person = {
  4. age : 24,
  5. name : "Yusuf"
  6. }
  7.  
  8. age, name = property
  9. 24, "Yusuf" = value
  10.  
  11. access object
  12. /////////////
  13. umur = person.age
  14. nama = person['name']
  15.  
  16. object method
  17. /////////////
  18. document.write("this is object method")
  19.  
  20.  
  21. object constructor
  22. ////////////////////
  23. function person(name,age){
  24. this.name = name;
  25. this.age = age;
  26. }
  27. var yusuf = new person("M Yusuf", 24)
  28. console.log(yusuf.age)
  29.  
  30. adding method at object
  31. /////////////
  32. function person(name, age){
  33. this.name = name;
  34. this.age = age;
  35. this.gantiNama = function(name){
  36. this.name = name;
  37. }
  38. }
  39.  
  40. let yusuf = new person("MYusuf", 24)
  41. yusuf.gantiNama("MuhYusuf")
  42.  
  43. ////
  44. javascript tidak support array assosiatif
Add Comment
Please, Sign In to add comment