I'm trying to make a class that has an optional parameter.
Is it possible to add a conditional such as if(!(degrees === undefined)) {this._items.degree = degrees}
When I try to do this, I get the error "SyntaxError: Unexpected identifier" upon declaring/creating the object.
var element = {
degree = 0;
}
var Radial = function(items, degrees) {
this._items = itemsfunction(); //_items is an element structure the function makes and returns the element
if (!(degrees===undefined)) { //where the error occurs
for (int i = 0; i<this._items.length; i++) {
if (!(degrees[i]===undefined)) {
this._items[i].degree = degrees[i];
} else {
this._items[i].degree = 0;
}
}
}
};
The above is my constructor
I declare it as so radial = new Radial(item, degrees); and radial = new Radial(item); and both return the same error of Unexpected identifier in the console, and the Radial object is not created. When I take out the if conditional, everything works.
What am I doing wrong? I'm new to javascript classes.
=in the object prop assignment. Should be: