dojo框架用hitch实现函数与上下文的绑定
发布时间:2020-12-16 21:26:07 所属栏目:百科 来源:网络整理
导读:dojo框架:http://dojotoolkit.org/ !DOCTYPEhtmlhtmlheadmetacharset="UTF-8"titledojo框架绑定函数与上下文/titlescriptsrc="dojo/dojo/dojo.js"/script/headbodyscriptrequire(["dojo/_base/lang"],function(lang){vartheAccumulator={total:0,clear:func
dojo框架:http://dojotoolkit.org/ <!DOCTYPEhtml> <html> <head> <metacharset="UTF-8"> <title>dojo框架绑定函数与上下文</title> <scriptsrc="dojo/dojo/dojo.js"></script> </head> <body> <script> require(["dojo/_base/lang"],function(lang){ vartheAccumulator={ total:0,clear:function(){ },clear:function(){ this.total=0; },add:function(x){ this.total+=x; },getResult:function(){ returnthis.total; } }; theAccumulator.clear(); theAccumulator.add(1); theAccumulator.add(2); functionprintResult(func){ console.log(func()); } printResult(lang.hitch(theAccumulator,"getResult"));//输出3 }); </script> </body> </html> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |