What are the methods to access javascript properties and methods?
- by admin
- 0
we can use dot and brackets to access the properties and methods.
function myobjs(){
this.name= “john”; //Property
this.age= “20”; //Property
this.nameandage= function(){ // Method
console.log(this.name+’with age’+this.age);
},
this.nickname=[“a”,”b”,”c”]; // using multiple values to a property , like array
this.allname=function(){
alert(“eachname”);
this.nickname.forEach(function(eachname){
alert(eachname);
});
}
}
var insta_myobj=new myobjs();
alert(insta_myobj[‘name’]); // brackets
insta_myobj.allname(); // dot
we can use dot and brackets to access the properties and methods. function myobjs(){ this.name= “john”; //Property this.age= “20”; //Property this.nameandage= function(){ // Method console.log(this.name+’with age’+this.age); }, this.nickname=[“a”,”b”,”c”]; // using multiple values to a property , like array this.allname=function(){ alert(“eachname”); this.nickname.forEach(function(eachname){ alert(eachname); }); } } var insta_myobj=new myobjs(); alert(insta_myobj[‘name’]); // brackets insta_myobj.allname(); // dot…
we can use dot and brackets to access the properties and methods. function myobjs(){ this.name= “john”; //Property this.age= “20”; //Property this.nameandage= function(){ // Method console.log(this.name+’with age’+this.age); }, this.nickname=[“a”,”b”,”c”]; // using multiple values to a property , like array this.allname=function(){ alert(“eachname”); this.nickname.forEach(function(eachname){ alert(eachname); }); } } var insta_myobj=new myobjs(); alert(insta_myobj[‘name’]); // brackets insta_myobj.allname(); // dot…