JSFiddle - React, Tailwind, and code Playground

by javascriptenlightenment

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<!-- disregard this pane, html is shown in the "result" pane -->




































































<h4><strong>&larr; Code Example from <a href="http://www.javascriptenlightenment.com/" target="_blank">JavaScript Enlightenment Book</a> by <a href="http://www.codylindley.com" target="_blank">Cody Lindley</a></strong></h4>

<p>JavaScript code is executed on page load. Click the "Run" button in the top bar to re-run the JavaScript code. Output is logged to the <a href="http://getfirebug.com/firebuglite" target="_blank">Firebug Lite</a> console below &darr;.</p>

JavaScript

// augment the built-in String constructor Function() with the augmentedProperties property
String.augmentedProperties = [];

if (!String.prototype.trimIT) { // if the prototype does not have trimIT() add it
    String.prototype.trimIT = function() {
        return this.replace(/^\s+|\s+$/g, '');
    }

    // now add trimIT string to the augmentedProperties array
    String.augmentedProperties.push('trimIT');
}
var myString = '  trim me  ';
console.log(myString.trimIT()); // logs 'trim me'

console.log(String.augmentedProperties.join()); // logs 'trimIT'