Last active
July 17, 2018 19:53
-
-
Save myusufid/30fde3af91cd8c906733c209ce6da958 to your computer and use it in GitHub Desktop.
Javascript Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment