kangax/fabric.js — pull request #1136 by msievers (2014-02-03 10:10:57+00:00)
Title: Fix race condition in fabric.parseElements by converting ElementsParser to a constructor function

I think there is a race condition in

```javascript
// parse.js
parseElements: function(elements, callback, options, reviver) {
fabric.ElementsParser.parse(elements, callback, options, reviver);
}
```
The problem is, that fabric.ElementsParser shares state between different calls off `loadSVGfrom...`

You can reproduce this isse by simply trying to load two SVGs in a row in kitchensink like this.

```javascript
// clear canvas
canvas.clear();

// remove currently selected object
canvas.remove(canvas.getActiveObject());

fabric.loadSVGFromURL('../lib/tiger2.svg', function(objects, options) {
var obj = fabric.util.groupSVGElements(objects, options);
obj.scale(0.5);
canvas.add(obj);
});

fabric.loadSVGFromURL('../lib/tiger2.svg', function(objects, options) {
var obj = fabric.util.groupSVGElements(objects, options);
obj.scale(0.5);
obj.top = 100;
canvas.add(obj);
});
```
The expected behaviour would be to see two tigers. But there's only one.

I think this can easily be solved be making fabric.ElementsParser a constructor function and create instances of it in parseElements. This way, each call of `loadSVGfrom...` creates a instance of fabric.ElementsParser with its own state, isolated from each other.

Two see, how kitchensink performs with these changes, execute the following in kitchensink.

```javascript
fabric = undefined;
$.getScript('https://rawgithub.com/msievers/fabric.js/parser_race_condition_dist/dist/fabric.js', function() {
// clear canvas
canvas.clear();

// remove currently selected object
canvas.remove(canvas.getActiveObject());

fabric.loadSVGFromURL('../lib/tiger2.svg', function(objects, options) {
var obj = fabric.util.groupSVGElements(objects, options);
obj.scale(0.5);
canvas.add(obj);
});

fabric.loadSVGFromURL('../lib/tiger2.svg', function(objects, options) {
var obj = fabric.util.groupSVGElements(objects, options);
obj.scale(0.5);
obj.top = 100;
canvas.add(obj);
});
});
```