Skip to content

Instantly share code, notes, and snippets.

@dickeylth
Created November 21, 2013 15:55
Show Gist options
  • Save dickeylth/7584184 to your computer and use it in GitHub Desktop.
Save dickeylth/7584184 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
function Person(){
// 缓存实例
var instance = this;
// 添加属性
this.attr = "Attribute";
// 重写该构造函数
Person = function(){
return instance;
};
}
Person.prototype.job = 'FE';
var p1 = new Person();
Person.prototype.city = 'Beijing';
var p2 = new Person();
console.log(p1);
console.log(p2);
console.log(p1.constructor === Person);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment