Function.prototype.setProperty >= 0.1.4
Purpose
Set a getter on the given prototype, or a simple value
Syntax
Function#setProperty
(
Stringname
Functiongetter
Functionsetter
);
Parameters
name
- The name of the property. The name of the getter is used by default.
getter
- Can be a function (getter) or a simple value
setter
Examples
Add a getter to a new class
var Person = Function.inherits(function Person(firstname, lastname) {
this.firstname = firstname;
this.lastname = lastname;
});
// Add the new property
Person.setProperty(function fullname() {
return this.firstname + ' ' + this.lastname;
});
// Create a new instance
var me = new Person('Jelle', 'De Loecker');
// Get the full name
console.log(me.fullname);>>> "Jelle De Loecker"
Comments