/** Traditional function have strong support for 'this', which we need here as we can see. Arrow functions do not have strong support for 'this'. Thus we choose to use a traditional function here.*/ String.prototype.capitalized = function() { /*Notes -- charAt is "soft" i.e. will return empty string for bad index slice() is also loose, e.g. (''.slice(1000)) returns '')*/ return this.charAt(0).toUpperCase() + this.slice(1); }
//Import file so that extensions are loaded
require('./extending-javascript-base-code');
console.log('boot'.capitalized());
String.prototype.capitalized = () => { /*Notes -- charAt is "soft" i.e. will return empty string for bad index slice() is also loose, e.g. (''.slice(1000)) returns '')*/ return this.charAt(0).toUpperCase() + this.slice(1); };