'How to assign variable value to an object property in javascript?
Consider this example: var v = 4; canvas.freeDrawingBrush.width = v;. I then change the value of v, and run canvas.freeDrawingBrush.width = v; again. The brush width changes as intended, however, it causes lots of bugs where some drawn paths are shifted or are partially erased. What am I doing wrong? Is it even allowed to initialize an objects property through a variable? (I am using fabric.js library).
EDIT: My original function looks like this:
switch (thickness) {
case "small-thickness":
v = smallThickness;
break;
case "medium-thickness":
v = mediumThickness;
break;
case "large-thickness":
v = largeThickness;
break;
default:
v = smallThickness;
}
pencilThickness = thickness;
canvas.freeDrawingBrush.width = v;
I change the value of smallThickness, and call this block of code again.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
