`
lg_asus
  • 浏览: 185200 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

js原型链继承和闭包例子

    博客分类:
  • 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>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics