Entwine has specific support for Properties.
Here is your example re-written to use them. In this example each element that matches ".myselector" will have it's own property called Container, which is set and gotten via the getter methods setContainer & getContainer.
$('.myselector').entwine({
Container: null,
onmatch: function() {
this.setContainer(this.closest('form'));
},
onchange: function() {
console.log(this.getContainer()) // undefined
}
});
However you should avoid using onmatch if possible - it can get quite slow when there are a lot of them. Here is a useful pattern that lazily sets the Container property the first time it's looked up, and then uses the set value after that:
$('.myselector').entwine({
Container: null,
getContainer: function() {
var container = this._super();
if (!container) this.setContainer(container = this.closest('form'));
return container;
},
onchange: function() {
console.log(this.getContainer()) // undefined
}
});