enyojs/enyo — pull request #503 by debianw (2013-10-15 21:49:12+00:00)
Title: Component bindings are not being completely destroyed after calling .destroy() method on a Component

Component bindings are not being completely destroyed after calling .destroy() method on a Component

``` javascript
var co = new enyo.Component({
name: "MyComponent",

prop1: "value of prop1",
prop2: "value of prop2",
prop3: "value of prop3",
prop4: "value of prop4",

components: [
{tag: "div", name: "prop1"},
{tag: "div", name: "prop2"},
{tag: "div", name: "prop3"},
{tag: "div", name: "prop4"}
],

bindings: [
{from: ".prop1", to: ".$.prop1.content"},
{from: ".prop2", to: ".$.prop2.content"},
{from: ".prop3", to: ".$.prop3.content"},
{from: ".prop4", to: ".$.prop4.content"}
]
});

co.destroy();

this.finish(
(co.bindings.length !== 0) && "did not remove all bindings"
);
```

The line giving the issue is: https://github.com/enyojs/enyo/blob/master/source/kernel/mixins/BindingSupport.js#L220

Solution would be to ensure the for loop iterates on all items of the Array `this.bindings`.

Check code bellow where variable `i` was replaced by `0` to ensure all items of the Array `this.bindings` are reached even after deleted items.

Even more I created a unit test to reproduce the issue. Please see code bellow `bindingTest.js`

The way of doing the condition inside the for loop is not a very good practice in combination with splice https://github.com/enyojs/enyo/blob/master/source/kernel/mixins/BindingSupport.js#L154 at the same time.

Example of the way Enyo is doing:

```
var bs = this.bindings;

if (bs) {
for (var i=0, b; (b=bs[i]); ++i) {
b.destroy();
}
}
```

Other methods might be affected by this practice.

Thank you.