UNPKG

hyp-nice

Version:

redefine the javascript original class and add nice or handy method

62 lines (50 loc) 1.1 kB
"use strict"; // exports.echo = function (str) { console.info(str) }; exports.toJSON = JSON.stringify; exports.fromJSON = JSON.parse; function redefineString() { String.prototype.endWith = function(str){ if(str==null||str==""||this.length==0||str.length>this.length) return false; if(this.substring(this.length-str.length)==str) return true; else return false; return true; }; String.prototype.startWith = function(str){ if(str==null||str==""||this.length == 0 || str.length > this.length) return false; if(this.substr(0,str.length)==str) return true; else return false; return true; }; String.prototype.trim= function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); }; } redefineString(); function redefineArray() { Array.prototype.removeFirst = Array.prototype.shift; /* Array.prototype.toJSON = function(){ console.log("aaaa"); return JSON.stringify(this); }*/ } redefineArray(); function redefineObject() { /* Object.prototype.toJSON = function(){ return JSON.stringify(this); }*/ } redefineObject();