Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update prototype.js

  • Loading branch information...
commit 1b934041d8336a512ffa1bdc78e96a792a5ec9ba 1 parent 7c16427
@lenbo-ma authored
Showing with 72 additions and 31 deletions.
  1. +72 −31 lib/prototype.js
View
103 lib/prototype.js
@@ -1,40 +1,81 @@
exports.string = function string () {
- String.prototype.trim = function () {
- return this.replace(/(^\s*)|(\s*$)/g, "");
- };
-
- String.prototype.ltrim = function () {
- return this.replace(/(^\s*)/g, "");
- };
-
- String.prototype.rtrim = function () {
- return this.replace(/(\s*$)/g, "");
- };
+ String.prototype.trim = function () {
+ return this.replace(/(^\s*)|(\s*$)/g, "");
+ };
+
+ String.prototype.ltrim = function () {
+ return this.replace(/(^\s*)/g, "");
+ };
+
+ String.prototype.rtrim = function () {
+ return this.replace(/(\s*$)/g, "");
+ };
};
exports.array = function array () {
- //去重
- Array.prototype.distinct = function(){
- var arr = [],
- obj = {},
- i = 0,
- len = this.length,
- result;
-
- for( ; i < len; i++ ){
- result = this[i];
- if( obj[result] !== result ){
- arr.push( result );
- obj[result] = result;
- }
- }
-
- return arr;
- };
+ /**
+ * Array#distinct
+ * @returns {Array}
+ */
+ Array.prototype.distinct = function(){
+ var arr = [],
+ obj = {},
+ i = 0,
+ len = this.length,
+ result;
+
+ for( ; i < len; i++ ){
+ result = this[i];
+ if( obj[result] !== result ){
+ arr.push( result );
+ obj[result] = result;
+ }
+ }
+
+ return arr;
+ };
+
+ /**
+ * Array#clear
+ * @returns {Array}
+ */
+ Array.prototype.clear = function clear() {
+ this.length = 0;
+ return this;
+ };
+
+ /**
+ * Array#first
+ * @returns {Array}
+ */
+ Array.prototype.first = function first() {
+ return this[0];
+ };
+
+ /**
+ * Array#last
+ * @returns {Array}
+ */
+ Array.prototype.last = function last() {
+ return this[this.length - 1];
+ };
+
+ /**
+ * Array#clone() -> Array
+ *
+ * Returns a duplicate of the array, leaving the original array intact.
+ **/
+ Array.prototype.clone = function clone() {
+ return slice.call(this, 0);
+ };
};
exports.date = function date () {
- //日期格式化
+ /**
+ * 日期格式化
+ * @param fmt
+ * @returns {Date}
+ */
Date.prototype.format = function (fmt) {
fmt = fmt || 'yyyy-MM-dd';
@@ -57,5 +98,5 @@ exports.date = function date () {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
return fmt;
- }
+ };
};
Please sign in to comment.
Something went wrong with that request. Please try again.