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>