码迷,mamicode.com
首页 > 其他好文 > 详细

扩展方法的应用

时间:2017-09-02 16:54:08      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:type   fun   nbsp   family   func   str   function   style   this   

通过类对象的Protype设置扩展方法

string.prototype.quote=function(srt){  }

string.prototype.自定位方法名=function(自定义参数)

{this........}

this代表,当调用方法时 比如:var 字符串=“aaa”  调用字符串.自定义方法(参考值)的时候,this就是这个字符串,也就是“aaa”

 

也可以不用扩展方法

比如:有

string.pvoperty.JiaA=

function(  ){

retnrn this+"A";}

调用 alevt("B".JiaA(  )<==>{var B="B";  alvet(B.Jia( ));}

等价于

function JiaA(str)

{return str+“A”}

调用  alvert (JiaA("B");

扩展方法的应用

标签:type   fun   nbsp   family   func   str   function   style   this   

原文地址:http://www.cnblogs.com/FJL1/p/7466734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!