当前位置: 代码迷 >> JavaScript >> js原形链继承和闭包例子
  详细解决方案

js原形链继承和闭包例子

热度:159   发布时间:2012-11-25 11:44:31.0
js原型链继承和闭包例子
 	<script type="text/javascript">
		Function.prototype.method = function(name,func){
			this.prototype[name] = func;
			return this;
		}
	
		String.method('deentityify',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;
					}
				);
			};
		}());

		document.writeln('&lt;&quot;&gt;'.deentityify());//<">
	
</script>
  相关解决方案