0

我有一个像这样的函数,我需要覆盖它。

myfunction.getExtraConfig=function() { 返回 {}; };

我需要传入一个对象并让它返回多个值。

我如何使用字典来做到这一点 {prop1: 1, prop2: 3}?

如何使用 dojo.mixin() 添加返回值?

有没有我可以参考的示例代码?

4

1 回答 1

1

Dojo's mixin function only mixes objects' properties. The return value in your getExtraConfig function is not an object property.

I'm not sure this is what you want, but one way to alter the return value from getExtraConfig is to use dojo/aspect:

define(["dojo/_base/lang", "dojo/aspect"], function(lang, aspect){
  //...
  aspect.after(myfunction, "getExtraConfig", function(original){
      return lang.mixin(original, {prop1: 1, prop2: 3});
  });
  //...
});
于 2013-04-18T17:34:55.423 回答