I have a web app, where the user can hit a button to copy
an engine object.
I wrote the method below in Javascript, and it works. However, if more than 2 or 3 users are cloning, random errors will pop-up. For example, it will say, Engine is undefined
or engineToClone is undefined
.
But if only one person is doing it, it never has errors.
So I am wondering if there is a better way to write this:
var engineToClone = this.model;
var clonedEngine = new Engine({
factoryId: engineToClone.attributes.factoryId,
title: 'CLONED OF - ' + engineToClone.attributes.title,
engineDescription: engineToClone.attributes.engineDescription,
isFrontend: engineToClone.attributes.isFrontend,
cylinders: engineToClone.cylinders,
headers: engineToClone.headers,
vehicles: engineToClone.vehicles,
pistons: engineToClone.pistons,
fuels: engineToClone.fuels
});
clonedEngine.save(null, {
url: self.factory.url()
}).done(function () {
});
I tried doing this, but it generates null values:
var engineToClone = this.model;
var clonedEngine = engineToClone;
But the clonedEngine is always comes back as null.
I also read an answer on here to use json, so I tried this:
JSON.parse(JSON.stringify(engineToClone))
But it always says JSON is undefined.
So I must be doing something wrong and I was hoping someone could point me in the right direction.
Thanks!