Easy API Mapping concept

memolus at googlemail.com memolus at googlemail.com
Sun Dec 27 04:21:59 PST 2009

This is my idea for an easy mapping concept:

First Example:

    this.__defineGetter__("modus", function() {
		return !gui.hidden;
	this.__defineSetter__("modus", function(modus) {
		return gui.hidden = !modus;

will be turned into:

	this.modus := function() { return !gui.hidden }

Second Example:

	this.__defineGetter__("input", function() {
		if (modus === true)
			return gui.input;
			return gui.placeholder_input;
	this.__defineSetter__("input", function(input) {
		if (modus === true)
			return gui.input = input;
			return gui.placeholder_input = input;

will be turned into:

	this.input := function() {
		if (modus === true)
			return gui.input;
			return gui.placeholder_input;

Third Example:

	this.__defineGetter__("name", function() {
		return "Bob";
	this.__defineSetter__("name", function(newName) {
		return "Bob"; // ignore newName

will be turned into

this.name := function() { return "Bob"; }

There also be the easier way:

this.name := "Bob";

You could also write:

let name = "Bob";
this.name := name;

Note that
	this.name := firstname + surname;
	this.name := function() { return firstname + sirname; }
are NOT equivalent. In the first example the operator will be executed
one time when the interpreter reads this line, in the second example
the function will always be called if you want to get or set
this.name. Note that 'this.name' and 'this.name="abc"' are equivalent
after you wrote the mentionend line. This is only a side-effect. The
real features are "dynamic references" and "references to primitive
data types".

dynamic references:
	You can get another reference each time you get or set the object

references to primitive data types:
	You can set an real reference to a String or a Number

These are all features important to API mapping.

More information about the es-discuss mailing list