Python语言里的method auto bind与JavaScript ES5显式function.bind语法
来源:互联网 发布:二六三网络通信 编辑:程序博客网 时间:2024/06/05 03:13
这个有意思的问题是最近发现的:
s = " 123abc " #前后加点空格;m = s.strip #取实例对象的成员方法引用m() #调用,这里将返回"123abc"
下面是JavaScript代码:
var s = " 123abc "undefinedvar m = s.trimundefinedm()VM807:1 Uncaught TypeError: String.prototype.trim called on null or undefined at trim (<anonymous>) at <anonymous>:1:1
JavaScript/ES5里需要这么做:
var m2 = s.trim.bind(s)undefinedm2()"123abc"
这个例子有助于理解JS里面this及ES5 bind的用法。
阅读全文
0 0
- Python语言里的method auto bind与JavaScript ES5显式function.bind语法
- ES5的Function新增的bind方法简单介绍
- 理解javascript的 Function.prototype.bind
- Javascript bind 与 jQuery bind
- bind与function(一)
- boost::function与boost::bind 的使用
- es5 bind和es3函数模拟的bind的区别
- javascript Function.propertype.bind 解析
- JavaScript 中的 Function.prototype.bind
- ES5新增函数之二: Function.prototype.bind();
- stl里的function和bind的实现
- std::bind与std::function
- Function bind
- 搞懂JavaScript的Function.prototype.bind[译]
- boost::function/bind 的使用
- Python里method和function的区别
- tr1::bind与tr1::function的用法与具体应用
- What is Bind method in JavaScript
- 6174问题
- 使用Ettercap filter进行流量监听和数据篡改
- CSU1086-超市购物-分组背包
- CSU1090-Number Transformation-BFS
- VMware虚拟机磁盘操作占用过高问题
- Python语言里的method auto bind与JavaScript ES5显式function.bind语法
- CSU1093-Caps Lock-模拟
- 使用python实现用微信远程控制电脑
- delphi xe 之路(14)使用FireMonkeyStyle
- [翻译]Django1.11 Writing your first Django app, part 1
- CSU1101-报数游戏-模拟、枚举
- Core Data 基本用法
- sscanf的高级用法
- CSU1777-大还是小?-模拟