This is a modular version of Dean Edward's Base.js. The script first checks to see if it is in an AMD environment and if it is defines an AMD module. If the current environment is not an AMD environment then the script checks to see if it is in a web browser and attaches the
Base constructor to the
window object. If those two tests fail then it is assumed that the script is running in a CommonJS environment and it assigns
module.exports to be a reference to the
In addition to modularizing the code I have also updated the entire implementation so that it passes JSHint (with default settings in the installed version -- the web version turns on
strict by default).
The first way to get started using the script is to simply include it wherever else you include scripts (be it at the top, bottom, through a script loader, or what have you):
The second way to get started is to include the script as a dependency for an AMD application or module (using something such as RequireJS):
The third and final way to get started is to
require the module in a CommonJS environment (such as node.js):
:::text npm install basejs
Then in your script you only need to do the following:
Moving forward, whichever path you chose above you should now have a
Base object to work with. Basic usage is as follows:
Notice the use of
this.base() is how you access the parent's method. This works in all methods (including constructors).
You can also define static (class-level) properties and methods:
For more details including private data and singleton objects check out Dean Edward's original documentation.
The MIT License
Based on Base.js 1.1a (c) 2006 - 2010 Dean Edwards
Updated to pass JSHint and converted into a Module format by Kenneth Powers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.