Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JavaScript Object
- //////////
- let person = {
- age : 24,
- name : "Yusuf"
- }
- age, name = property
- 24, "Yusuf" = value
- access object
- /////////////
- umur = person.age
- nama = person['name']
- object method
- /////////////
- document.write("this is object method")
- object constructor
- ////////////////////
- function person(name,age){
- this.name = name;
- this.age = age;
- }
- var yusuf = new person("M Yusuf", 24)
- console.log(yusuf.age)
- adding method at object
- /////////////
- function person(name, age){
- this.name = name;
- this.age = age;
- this.gantiNama = function(name){
- this.name = name;
- }
- }
- let yusuf = new person("MYusuf", 24)
- yusuf.gantiNama("MuhYusuf")
- ////
- javascript tidak support array assosiatif
Add Comment
Please, Sign In to add comment