-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjects.js
More file actions
48 lines (36 loc) · 1.04 KB
/
objects.js
File metadata and controls
48 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var myDetails = new Object()
myDetails.name = "Manjula"
myDetails.age = 25
myDetails.profession
//we also have bracket notation
myDetails['address'] = 'kandivali'
function showDetails(obj,objName){
var results = ''
for(var i in obj){
if(obj.hasOwnProperty(i)){
results += objName + "." + i + " = " + obj[i] + "\n"
}
}
return results
}
console.log(showDetails(myDetails,"myDetails"))
// object initializer
var myDetails = {name: "Manjula",age: 25,profession:"software developer"}
//constructor function
function myDetails(name,age,profession){
this.name = name
this.age = age
this.profession = profession
}
var mydetail = new myDetails("Mnajula",26,"Software Engineer")
var myanotherdetail = new myDetails("Sample",26,"Software Engineer")
console.log(myanotherdetail)
myanotherdetail.test = "i am test"
//Object.create
var myDetails = {
name: "Manjula",age: 25, profession: "Software developer","displayName":function(){
console.log(this.name)
}
}
var detail = Object.create(myDetails)
console.log(detail.name)