标签:
1. 扩充类型的功能
Function.prototype.method = function(name, func){
if(!this.prototype[name]){ this.prototype[name] = func;
} return this; }
String.method(‘deentityfy‘,function(){ var entity={ quot:‘"‘, lt:‘<‘, gt:‘>‘ }; return function(){ return this.replace(/&([^&;]+);/g, function(a,b){ var r = entity[b]; return typeof r===‘string‘ ? r:a; }); }; }()); console.log(‘<>‘.deentityfy()); // <>
标签:
原文地址:http://www.cnblogs.com/lcw5945/p/4329807.html