Skip to content

Snip: Processing on get set

John Weiss edited this page May 15, 2020 · 1 revision

JS:

var home = {
	cit : "Boston",
	get City () {
		return this.cit.toLowerCase();
	},
	set City(val) {
		this.cit = 'City: ' + val;
	}
};

CONTEXT:

home
    City "Boston"
        .toLowerCase
        'City: ' .

Rules in this lite syntax:

  • get and set are expected to be defined in order, so you don't have to say get or set.
  • Default value is written after the member name.
  • "private" variable is unstated
  • Write the processing methods or functions for get and set without mentioning the parameter or "private" variable. It's assumed.
  • . Dot is an alias for the parameter passed into set by the caller.
  • Eliminate + with a rule that says "a string followed by a value is assumed to be a concatenation."
object
    member defaultValue
        getProcessing
        setProcessing