console
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
const Person = (function () {
function Person(name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
Person.prototype.say = function say() {
console.log('say hello')
}
let instance = null;
return function (...args) {
if (!instance) instance = new Person(...args);
return instance;
}
})();
let p1 = new Person('Henry', 18, 'male')
let p2 = new Person()
console.log(p1, p2)
console.log(p1 === p2)
</script>
</body>
</html>