get property()
Specify a property's get behavior with the get syntax.
import { ObservableObject } from "can/everything";
class Example extends ObservableObject {
get propertyName() {
return true;
}
}
const e = new Example();
console.log( e.propertyName ); //-> true
For example:
import { ObservableObject } from "can/everything";
class Person extends ObservableObject {
static props = {
first: String,
last: String
};
get fullName() {
return this.first + " " + this.last;
}
}
const person = new Person( {first: "Justin", last: "Meyer"} );
console.log( person.fullName ); //-> "Justin Meyer"
This is a shorthand for providing an object with a get
property like:
import { ObservableObject } from "can/everything";
class Person extends ObservableObject {
static props = {
first: String,
last: String,
fullName: {
get() {
return this.first + " " + this.last;
}
}
}
}
const person = new Person( {first: "Justin", last: "Meyer"} );
console.log( person.fullName ); //-> "Justin Meyer"
You must use an object with a get property if you want your get to take the lastSetValue
or resolve
arguments.