JavaScript:如何修复未正确分配属性值的实例

JavaScript:如何修复未正确分配属性值的实例,javascript,class,oop,object,properties,Javascript,Class,Oop,Object,Properties,我创建了我的工件类的一个实例,并试图打印出该实例的数量的值,但我一直没有定义 我在GoogleChrome控制台中查看,发现console.log(temp)很好,但在我看来,它似乎没有分配任何属性值。(我认为如果单击实例的下拉箭头,它应该显示属性和值,对吗?) 我还console.log(长度)和console.log(数量),它们打印得很好 <!DOCTYPE html> <html lang="en"> <head> <meta chars

我创建了我的
工件
类的一个实例,并试图打印出该实例的
数量
的值,但我一直没有定义

我在GoogleChrome控制台中查看,发现
console.log(temp)
很好,但在我看来,它似乎没有分配任何属性值。(我认为如果单击实例的下拉箭头,它应该显示属性和值,对吗?)

我还
console.log(长度)
console.log(数量)
,它们打印得很好

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Parker Steel Program</title>
    <link rel="stylesheet" href="./main.css">
    <script src="./form.js"></script>
    <script src="./order.js"></script>
</head>
<body>
    <h1>Parker Steel Company</h1>
    <h2>New Order</h2>
    <form id="order-info">
        <label for="stock-length">Stock Length:</label>
        <input autofocus="true" id="stock-length" name="stock-length" required="true" type="number">
        <fieldset id="line1" name="line-1">
            <label for="line-1-length">Length: </label>
            <input id="line-1-length" name="line-1-length" required="true" type="number">
            <label for="line-1-quantity">Quantity: </label>
            <input id="line-1-quantity" name="line-1-quantity" required="true" type="number">
            <button onclick="removePurchaseLine('line1')" type="button">Remove</button>
        </fieldset>
        <button id="add-purchase-line" name="add-purchase-line" onclick="addPurchaseLine()" type="button">Add Purchase Line</button>
        <button onclick="getBestCuttingSequence()" type="button">Calculate</button>
    </form>
</body>
</html>

帕克钢铁计划
帕克钢铁公司
新秩序
库存长度:
长度:
数量:
去除
添加购买行
算计
类块{
构造(长度、数量){
这个长度=长度;
这个。数量=数量;
}
}
函数getBestCutingSequence(){
const stockLength=document.getElementById(“stock length”).value;
const pieces=getPieces();
}
函数getPieces(){
常数件=[]
const numPurchaseLines=document.getElementsByTagName(“字段集”).length;

对于(让purchaseLine=1;purchaseLine几乎没有输入错误。
constructor
缺少
r
。请更改它将起作用

然而,您正在向
添加属性而不进行修改,您可以传递对象,然后传递
对象。分配

class Piece {
    constructor(obj) {
        Object.assign(this,obj);
    }
}
然后像这样通过

let temp = new Piece({length, quantity});

我试过了,但仍然不起作用。对不起,我忘了编辑这段代码。我会进行编辑。我不敢相信我错过了。谢谢你的帮助!
let temp = new Piece({length, quantity});