开发者

Extending object

开发者 https://www.devze.com 2023-03-14 18:49 出处:网络
I want to extend object in dojo similar to this from jQuery var x = $.extend({}, obj1, obj2); Is this a solution

I want to extend object in dojo similar to this from jQuery

var x = $.extend({}, obj1, obj2);

Is this a solution

var x;
dojo.extend(x,obj1);
dojo.extend(x,obj2);

Or can I do

dojo.extend(x,obj1,obj2);

Is this available

var x = dojo.exten开发者_开发知识库d(obj1, obj2);


If you want to implement the same semantics as $.extend(), you have to use dojo.mixin() instead of dojo.extend() (which extends prototypes):

var x = dojo.mixin({}, obj1);
dojo.mixin(x, obj2);

EDIT: If you want to keep the code on one line, you can do:

var x = dojo.mixin(dojo.mixin({}, obj1), obj2);
0

精彩评论

暂无评论...
验证码 换一张
取 消