我尝试了几件事,包括使用构造函数和下面的代码,都没有奏效。我以为这很简单,我该怎么做?
<!DOCTYPE html>
<html>
<body>
<p>Creating a JavaScript Object.</p>
<p id="demo"></p>
<script>
var name ={ // subobject
firstName : "John",
lastName : "Doe",
};
var person = {
name: {} // want to append here
};
person.name = name;
document.getElementById("demo").innerHTML =
person.name.firstName + " " + person.name.lastName;
</script>
</body>
</html>