Если вы хотите сократить инициализацию конструктора, то к одному способу создания свойств с тем же именем, что и аргументы, можно обратиться, используя Object.assign () и сокращенные имена свойств (но учтите, что это и функция ES6
, поэтому рекомендуется проверить совместимость браузера перед его использованием), например:
function SimpleCable(X, Y, totalRadius, outerRadius, innerRadius, type, name)
{
Object.assign(
this,
{center: [X, Y], totalRadius, outerRadius, innerRadius, type, name}
);
}
Пример
function SimpleCable(X, Y, totalRadius, outerRadius, innerRadius, type, name)
{
Object.assign(
this,
{center: [X, Y], totalRadius, outerRadius, innerRadius, type, name}
);
}
let cable1 = new SimpleCable(1, 2, 4, 5, 4,"type1", "name1");
console.log("cable1 is:", cable1);
let cable2 = new SimpleCable(7, 6, 7, 3, 2, "type2", "name2");
console.log("cable2 is:", cable2);
.as-console {background-color:black !important; color:lime;}
.as-console-wrapper {max-height:100% !important; top:0;}