get
special operatorS2C Home « Operators « get
Property binding.
Description
The get
special operator allows us to bind an object property to a function. When that property is accessed the function will be called.
Syntax
Signature | Description |
---|---|
{get propName() { . . . } } | Special operator which allows us to bind an object property to a function. |
Parameters
Parameter | Description |
---|---|
propName | The property name to bind to the function. |
Examples
Following is an examples of the get
special operator.
// The get operator.
function HomeOwner(firstName,lastName) {
this.firstName=firstName;
this.lastName=lastName;
aName = {
get fullname() {
return this.name;
},
name: this.firstName + ' ' + this.lastName
}
}
var aName;
owner = new HomeOwner('Barney','Magrew');
alert(aName.fullname);
owner = new HomeOwner('Manny','Simon');
alert(aName.fullname);
Related Tutorials
JavaScript Basic Tutorials - Lesson 7 - Objects