无法读取属性';设置';javascript中未定义的

无法读取属性';设置';javascript中未定义的,javascript,fabricjs,Javascript,Fabricjs,我正在使用fabric3.4创建一个canvas元素,该元素提供klass对象 比如,我有一个变量aas a = klass {lockScalingX: true} 我正在将其克隆到b,并用一些dictionary对象更新b b = a.clone(); b.set({lockMovementY: true}); 但这是一个错误 index.html:3 ERROR TypeError: Cannot read property 'set' of undefined 当我控制台记录a和b

我正在使用
fabric3.4
创建一个canvas元素,该元素提供
klass
对象

比如,我有一个变量
a
as

a = klass {lockScalingX: true}
我正在将其克隆到
b
,并用一些dictionary对象更新b

b = a.clone();
b.set({lockMovementY: true});
但这是一个错误

index.html:3 ERROR TypeError: Cannot read property 'set' of undefined
当我控制台记录
a
b
时。克隆后的b是未定义的

如何克隆
klass
对象并使用
set()
更新值?

或将结构的
klass
更改为简单对象?

编辑2

这是控制台日志的屏幕截图

这是一个阵列,控制台有8、9、10键打印。我已展开
8
,以显示键中包含的值

b[s] = a[s].clone();
console.log('a: ', a);        // This consoles the first code in the question.
console.log('b[s]: ', b[s]);  // This prints undefined

b[s].set({lockMovementY: true});  // This is giving error. Cannot read property set of undefined.

我通过调用fabric的
toObject()
方法解决了这个问题

早些时候,我使用的是fabric 1.x,正在进行项目改造。在将fabric升级到3.x之后,我开始面临这个问题。创建结构画布时,返回类型为
klass
的对象

const canvas = new fabric.Canvas();
为了将
klass
转换为object,我使用了
toObject()
方法

canvas.toObject()

它返回简单对象,而不是
klass
对象。

a=klass{lockScalingX:true}
似乎是无效的javascript。你想用这行代码做什么?你是说
a=new-klass({lockScalingX:true})
a
是一个
新结构。Canvas
对象。当我控制台
a
时,它给出
klass
为灰色的输出。我没有写
klass
它是控制台输出。你能附上你的代码,而不是控制台输出吗?请检查编辑2部分。不可能发布整个代码,因为调用正在许多文件中移动。我已经添加了代码摘要。