日期:2014-05-16 浏览次数:20480 次
var Abstract = new Object(); Object.prototype.extend1 = function(object) { for (property in object) { this[property] = object[property]; } return this; } Function.prototype.bind1 = function(object) { var method = this; return function() { method.apply(object, arguments); } } Function.prototype.bindAsEventListener = function(object) { var method = this; return function(event) { method.call(object, event || window.event); } } var Try = { these: function() { var returnValue; for (var i = 0; i < arguments.length; i++) { var lambda = arguments[i]; try { returnValue = lambda(); break; } catch (e) {} } return returnValue; } } /*--------------------------------------*/ var PeriodicalExecuter = Class.create(); PeriodicalExecuter.prototype = { initialize: function(callback, frequency) { this.callback = callback; this.frequency = frequency; this.currentlyExecuting = false; this.registerCallback(); }, registerCallback: function() { setTimeout(this.onTimerEvent.bind1(this), this.frequency * 1000); }, onTimerEvent: function() { if (!this.currentlyExecuting) { try { this.currentlyExecuting = true; this.callback(); } finally { this.currentlyExecuting = false; } } this.registerCallback(); } } //--------------------------------------string----------------------------------------- String.prototype.lTrim = function () {return this.replace(/^\s*/, "");} String.prototype.rTrim = function () {return this.replace(/\s*$/, "");} String.prototype.trim = function () {return this.rTrim().lTrim();} String.prototype.endsWith = function(sEnd) {return (this.substr(this.length-sEnd.length)==sEnd);} String.prototype.startsWith = function(sStart) {return (this.substr(0,sStart.length)==sStart);} String.prototype.format = function() { var s = this; for (var i=0; i < arguments.length; i++) { s = s.replace("{" + (i) + "}", arguments[i]);} return(s);} String.prototype.removeSpaces = function() { return this.replace(/ /gi,'');} String.prototype.removeExtraSpaces = function() { return(this.replace(String.prototype.removeExtraSpaces.re, " "));} String.prototype.removeExtraSpaces.re = new RegExp("\\s+", "g"); String.prototype.removeSpaceDelimitedString = function(r) { var s = " " + this.trim() + " "; return s.replace(" " + r,"").rTrim();} String.prototype.isEmpty = function() {return this.length==0;}; String.prototype.validateURL = function() { var urlRegX = /[^a-zA-Z0-9-]/g; return sURL.match(urlRegX, "");} String.prototype.isEmail = function() { var emailReg = /^\w+([-.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; return emailReg.test(this);} String.prototype.isAlphaNumeric = function() { var alphaReg = /[^a-zA-Z0-9]/g; return !alphaReg.test(this);} String.prototype.encodeURI = function() { var returnString; returnString = escape( this ) returnString = returnString.replace(/\+/g,"%2B"); return returnString } String.prototype.decodeURI = function() {return unescape(this)} //--------------------------------------Array----------------------------------------- Array.prototype.indexOf = function(p_var) { for (var i=0; i<this.length; i++) { if (this[i] == p_var) { return(i); } } return(-1); } Array.prototype.exists = function(p_var) {return(this.indexOf(p_var) != -1);} Array.prototype.queue = function(p_var) {this.push(p_var)} Array.prototype.dequeue = function() {return(this.shift());} Array.prototype.removeAt = function(p_iIndex) {return this.splice(p_iIndex, 1);} Array.prototy