ericdrowell/KineticJS — pull request #358 by MRdNk (2013-03-31 10:37:12+00:00)
Title: Sprite index: Default Index 0

Noticed that Sprite doesn't start with a default index of 0, errors if not set.

Error:
```javascript
sprite.js:50
Uncaught TypeError: Cannot read property 'x' of undefined kinetic-v4.4.0.min.js:30
Kinetic.Sprite.drawFunc kinetic-v4.4.0.min.js:30
Kinetic.Shape.drawScene kinetic-v4.4.0.min.js:29
Kinetic.Container.drawScene kinetic-v4.4.0.min.js:29
Kinetic.Node.draw kinetic-v4.4.0.min.js:28
Kinetic.Stage.add kinetic-v4.4.0.min.js:29
```

When index not set on Sprite:
```javascript
var blob = new Kinetic.Sprite({
x: 250,
y: 40,
image: imageObj,
animation: 'idle',
animations: animations,
frameRate: 7
});
```

This has broken the tutorial on html5canvastutorials.com
http://www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-sprite-tutorial/

----
I could see a couple of ways of solving this, originally I went with setting attrs.index as 0 by default.

Then noticed that the Sprite has an index attribute that is zero by default, therefore my approach was to change the code to refer to the Sprite's index, and use setIndex to update if attrs.index config was passed in.

I've added a unit test, which passes and runs, but please check this, as I'm not sure my unit test was written very well.

Happy to rewrite the alternative way, if that's the originally intention.