How To Get Properties Of The Object Subjected To Event Using Fabric.js?
Using Fabric.js 1.1.6, I have the following: var rect = new fabric.Rect({}); rect.on('moving', function(obj) { // I want to retrieve and set properties from the // object r
Solution 1:
"Is it possible to retrieve and modify the rect properties from inside the function called by the event?"
Not only it is possible but it is very simple ;) You should read about closures in JavaScript.
For question #1
var rect = new fabric.Rect({});
rect.on('moving', function(obj) {
rect.someProperty = 'test';
});
For question #2
functionSomeClass() {
var rect = this.rect = new fabric.Rect({});
this.rect.on('moving', function(obj) {
// here, this.rect is undefined
rect.someProperty;
});
}
Post a Comment for "How To Get Properties Of The Object Subjected To Event Using Fabric.js?"