Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                    
                
        

我坚持这一点:

var Names = function (name,integer) {
    this.name = name;
    this.integer = integer;
};

var Discount = {
    applyDiscount: function(person) {
        console.log("person name is: "    + person);            //Eve
        console.log("person integer is: " + person["integer"]); //undefined
        console.log("person integer is: " + Eve["integer"]);    // 23
    }
};

var Eve = new Names("Eve Something", 23);

Discount.applyDiscount("Eve");


当我尝试获取Eve.integer值(使用person参数)时-我已经获得undefined

为什么person["integer"]在这种情况下不起作用?

最佳答案

您将字符串"Eve"传递给函数,而不是变量Eve指向的对象。删除引号。

10-06 00:56