<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
<script>
function person() {
this.name = 'd1';
this.getName = function () {
return name;
};
this.setName = function (newName) {
name = newName;
};
}
console.log(new person().getName());
console.log(new person());
var p = new person();
console.log(p instanceof person);
</script>
<script>
function Person() {
this.name = 'd2';
return {
getName: function () {
return name;
},
setName: function (newName) {
name = newName;
}
}
}
console.log(new Person().getName());
console.log(new Person());
var p = new Person();
console.log(p instanceof Person);
p.setName("Tom");
console.log(p.getName());
</script>
</html>