Skip to content
Permalink
Browse files
alt versions of isArray if available, isDate uses instanceof, clean u…
…p extend and close
  • Loading branch information
purplecabbage committed Jul 25, 2015
1 parent aa0e6ae commit 74324b2134bf3f54179c6e92a53360b712e86fe2
Showing 1 changed file with 23 additions and 25 deletions.
@@ -78,15 +78,14 @@ utils.typeName = function(val) {
/**
* Returns an indication of whether the argument is an array or not
*/
utils.isArray = function(a) {
return utils.typeName(a) == 'Array';
};
utils.isArray = Array.isArray ||
function(a) {return utils.typeName(a) == 'Array';};

/**
* Returns an indication of whether the argument is a Date or not
*/
utils.isDate = function(d) {
return utils.typeName(d) == 'Date';
return (d instanceof Date);
};

/**
@@ -120,17 +119,25 @@ utils.clone = function(obj) {
* Returns a wrapped version of the function
*/
utils.close = function(context, func, params) {
if (typeof params == 'undefined') {
return function() {
return func.apply(context, arguments);
};
} else {
return function() {
return func.apply(context, params);
};
}
return function() {
var args = params || arguments;
return func.apply(context, args);
};
};

//------------------------------------------------------------------------------
function UUIDcreatePart(length) {
var uuidpart = "";
for (var i=0; i<length; i++) {
var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
if (uuidchar.length == 1) {
uuidchar = "0" + uuidchar;
}
uuidpart += uuidchar;
}
return uuidpart;
}

/**
* Create a UUID
*/
@@ -142,6 +149,7 @@ utils.createUUID = function() {
UUIDcreatePart(6);
};


/**
* Extends a child object from a parent object using classical inheritance
* pattern.
@@ -151,6 +159,7 @@ utils.extend = (function() {
var F = function() {};
// extend Child from Parent
return function(Child, Parent) {

F.prototype = Parent.prototype;
Child.prototype = new F();
Child.__super__ = Parent.prototype;
@@ -170,16 +179,5 @@ utils.alert = function(msg) {
};


//------------------------------------------------------------------------------
function UUIDcreatePart(length) {
var uuidpart = "";
for (var i=0; i<length; i++) {
var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
if (uuidchar.length == 1) {
uuidchar = "0" + uuidchar;
}
uuidpart += uuidchar;
}
return uuidpart;
}


0 comments on commit 74324b2

Please sign in to comment.