Skip to content

Instantly share code, notes, and snippets.

@myusufid
Last active July 17, 2018 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myusufid/30fde3af91cd8c906733c209ce6da958 to your computer and use it in GitHub Desktop.
Save myusufid/30fde3af91cd8c906733c209ce6da958 to your computer and use it in GitHub Desktop.
Javascript Object
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