1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <script type="text/javascript">
function Fn() { } Fn.prototype.a = 'xxx'; var fn1 = new Fn(); console.log(fn1.a, fn1);
var fn2 = new Fn(); fn2.a = 'yyy'; console.log(fn1.a, fn2.a, fn2);
function Person(name, age) { this.name = name; this.age = age; } Person.prototype.setName = function (name) { this.name = name; } var p1 = new Person('Tom', 12); p1.setName('Bob'); console.log(p1);
var p2 = new Person('Jack', 12); p2.setName('Cat'); console.log(p2); console.log(p1.__proto__===p2.__proto__);
</script>
|