我在使用一些基本的javascript时遇到了一些麻烦:
function tank(){
this.width = 50;
this.length = 70;
}
function Person(job) {
this.job = job;
this.married = true;
}
var tank1 = tank();
console.log(tank1.length); //returns: Uncaught TypeError: Cannot read property 'length' of undefined
var gabby = new Person("student");
console.log(gabby.married); //returns: true
Run Code Online (Sandbox Code Playgroud)
第一个console.log不起作用,但第二个console.log工作.我是一个javascript初学者,我不知道为什么长度属性是未定义的.有帮助吗?