JavaScriptでのレプリケーション継承
898 ワード
<script type="text/javascript">
$(function () {
//
function Tiger() {
this.addr = "dongbei";
this.climb = " ";
}
// Tiger extend
Tiger.prototype.extend = function (obj) {
// obj
for (var i in obj) {
// extend
//
if (this[i] == undefined) {
this[i] = obj[i];
}
}
}
var kitty = {color: 'yellow', climb: ' '};
var black = new Tiger();
// kitty black
black.extend(kitty);
console.log(black);
});
</script>