Utility.js

Contains Utility functions

Author

Valerio Proietti, http://mad4milk.net

License

MIT-style license.

Summary
Utility.jsContains Utility functions
Functions
$chkReturns true if the passed in value/object exists or is 0, otherwise returns false.
$pickReturns the first object if defined, otherwise returns the second.
$randomReturns a random integer number between the two passed in values.
$clearclears a timeout or an Interval.
windowSome properties are attached to the window object by the browser detection.

Functions

$chk

function $chk(obj)

Returns true if the passed in value/object exists or is 0, otherwise returns false.  Useful to accept zeroes.

$pick

function $pick(obj,
picked)

Returns the first object if defined, otherwise returns the second.

$random

function $random(min,
max)

Returns a random integer number between the two passed in values.

Arguments

mininteger, the minimum value (inclusive).
maxinteger, the maximum value (inclusive).

Returns

a random integer between min and max.

$clear

function $clear(timer)

clears a timeout or an Interval.

Returns

null

Arguments

timerthe setInterval or setTimeout to clear.

Example

var myTimer = myFunction.delay(5000); //wait 5 seconds and execute my function.
myTimer = $clear(myTimer); //nevermind

See also

Function.delay, Function.periodical

window

Some properties are attached to the window object by the browser detection.

Properties

window.iewill be set to true if the current browser is internet explorer (any).
window.ie6will be set to true if the current browser is internet explorer 6.
window.ie7will be set to true if the current browser is internet explorer 7.
window.khtmlwill be set to true if the current browser is Safari/Konqueror.
window.geckowill be set to true if the current browser is Mozilla/Gecko.
function $chk(obj)
Returns true if the passed in value/object exists or is 0, otherwise returns false.
function $pick(obj,
picked)
Returns the first object if defined, otherwise returns the second.
function $random(min,
max)
Returns a random integer number between the two passed in values.
function $clear(timer)
clears a timeout or an Interval.
Delays the execution of a function by a specified duration.
Executes a function in the specified intervals of time