A basic widget implementation

The following code is a very simply widget to generate a greeting. This example does not make use of any of the helpful factory classes, so it has to implement all the core widget requirements itself.

E.widget.greeting = class {

	constructor( str ) {
		this.n = "";
		this.name( str );
	}

	name( str ) {
		if( !E.empty( str ) ) {
			this.n = str.toString();
		}
		return this;
	}
	
	build() {
		return `<p>Hello, my name is <strong>${this.n}</strong>.</p>`;
	}

	append( t ) {
		if( !E.empty( t ) ) {
			$( t ).append( this.build() );
			return true;
		}
		return false;
	}

};

You would use this widget like so:

$E('greeting').name('Entegre IO').append('body');

Which will result in your document looking like this:

<!DOCTYPE html>
<html>
	<head>
		...
	</head>
	<body>
		...
		<p>Hello, my name is <strong>Entegre IO</strong>.</p>
	</body>
</html>
Last modified: 2016-02-05