Opt-In prototype helper functions
This toolset was designed to provide the ease-of-use and legibility of prototypal methods, without actually modifying the core objects, or bloating all variables of that constructor type. It does this by providing short-hand 'wrappers' for different data types which extend JavaScript's native functionality during those chained calls.
The wrappers currently available:
- Array:
A(myArray)
orA([1,2,3])
- Object:
O(myObj)
orO({a:1, b:2})
- String:
S(myStr)
orS("some string")
- Node:
N(myNode)
orN("node selector")
- Event:
E(event)
- Number/Digits:
D(myNum)
orD(3.5)
It also includes some standard functions used internally, but also useful outside of the wrappers:
df(variable)
- returns whether or notvariable
is defined.df(variable,"boolean")
- returns whether or notvariable
is of type "boolean"df(variable,"boolean",true)
- returnsvariable
if it is boolean, otherwise returnstrue
addEvent(element,'click',callback)
- attaches thecallback
to aclick
event on theelement
, selectingaddEventListener
orattachEvent
as appropriategetEvent(event)
- returns the same event object (or window.event if invalid), but ensures thatevent.target
is set (basically just a safe event referencer in an event handler when supporting older browsers)