Created
September 21, 2018 12:21
-
-
Save malikkurosaki/e3b4be9f0b0123d4d6ef836121f87c2a to your computer and use it in GitHub Desktop.
contoh model object javascrip
This file contains hidden or 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
// object model | |
var objectModel = { | |
nama:"paijo", | |
satu:function(){ | |
this.nama += "gunawan"; | |
}, | |
get namaNya(){ | |
return this.nama; | |
} | |
} | |
objectModel.satu(); | |
console.log(objectModel.namaNya) | |
//object chaining | |
function orang() { | |
this.nama = "paijo : "; | |
this.sodara = function (tambah) { | |
nama += " sodaranya:" + tambah ; | |
return this; | |
} | |
this.adik = function (tambah) { | |
nama += " adiknya:" +tambah ; | |
console.log(nama) | |
return this; | |
} | |
return this; | |
} | |
orang().sodara("andi").adik("nita"); | |
//bonus | |
String.prototype.namaLengkap = function (params) { | |
var ini = this + params; | |
return ini; | |
} | |
var siapa = "malik"; | |
console.log(siapa.namaLengkap("yaumiddin")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment