| constructor: function( | allowOverride | ) |
|
Class constructor, which simply performs extension of the JavaScript built in objects String, Date, and Number. If you want to extend JavaScript, you’d generally call this wherever your application/site specific logic is contained.
Arguments
| allowOverride | boolean (false by default), if true, allows the extender to override certain existing functions with new ones. Presently only Date.parse is overridden, since the built in function isn’t particularly useful. If this is false, alternative function names are used. |
Example
new Jel.CoreExtender(true);
Date.parse("23/05/2007", "d/m/Y");
// Date object with properties day = 23, month = 4, year = 2007
"white space ".trim(); // "white space"
How JavaScript core is extended by Jel
Most functions in Jel.String, Jel.Date, and Jel.Number have as their first argument an object of the equivalent type, upon which the operation is performed. JavaScript prototype extensions simply call the the equivalent function in Jel, with “this” as the first argument, followed by any additional arguments passed to the prototype function. For example, here is the code for the String.prototype.right function:
String.prototype.right = function(length) { return Jel.String.right(this, length) };
This now allows us to call right on a string directly, which is definitely convenient...
"Maximus".right(3); // "mus"
// as opposed to Jel.String.right("Maximus", 3);
Refer to the function mapping table below, to see the names of functions introduced to the core JavaScript objects. They follow the general rule above where the names of the functions match up, but with some exceptions (marked with *).
Function Mappings
String.prototype.repeat(count) => Jel.String.repeat(str, count)
String.prototype.right(length) => Jel.String.right(str, length)
String.prototype.left(length) => Jel.String.left(str, length)
String.prototype.trim() => Jel.String.trim(str, length)
String.prototype.ltrim() => Jel.String.ltrim(str)
String.prototype.rtrim() => Jel.String.rtrim(str)
String.prototype.toFloat() => Jel.String.toFloat(str)
String.prototype.toInt() => Jel.String.toInt(str)
String.prototype.extractInt() => Jel.String.extractInt()
String.prototype.eq(strCompare, ignoreCase) => Jel.String.eq(str, strCompare, ignoreCase)
String.prototype.decamelizeDelimiter(delimiter) => Jel.String.decamelize(str, delimiter)
String.prototype.camelizeDelimiter(delimiter) => Jel.String.camelize(str, delimiter)
String.prototype.titleCase() => Jel.String.titleCase(str)
String.prototype.normalize() => Jel.String.normalize(str)
String.prototype.constant() => Jel.String.constant(str)
String.prototype.parseDate(format) * => Jel.Date.parse(str, format)
String.prototype.convertDate(fromFormat, toFormat) * => Jel.Date.convert(str, fromFormat, toFormat)
Number.prototype.leadingZero(toLength) => Jel.Number.leadingZero(number, toLength)
Number.prototype.ordinalSuffix() => Jel.Number.ordinalSuffix(number)
Number.prototype.format(format) => Jel.Number.format(number, format)
Date.parseDate(str, format) * => Jel.Date.parse(str, format) OR
Date.parse(str, format) => Jel.Date.parse(str, format) (allowOverride true)
Date.convert(str, fromFormat, toFormat) => Jel.Date.convert(str, fromFormat, toFormat)
Date.prototype.format(format) => Jel.Date.format(date, format)
Date.prototype.daysInMonth() => Jel.Date.daysInMonth(month)
Date.prototype.isLeapYear() => Jel.Date.isLeapYear(year)
Date.prototype.meridiem() => Jel.Date.meridiem(hour)
Date.prototype.ordinalSuffix() => Jel.Date.ordinalSuffix(day)
Date.prototype.fullYear() => Jel.Date.fullYear(date)
Date.prototype.dayOfYear() => Jel.Date.dayOfYear(date)
Date.prototype.internetBeat() => Jel.Date.internetBeat(date)
ENGLISH SPECIFIC (if available)
String.prototype.an => Jel.String.an(str)
String.prototype.plural(count) => Jel.String.plural(str, count)