Douglas Crockford dường như thích cách tiếp cận thừa kế sau:Javascript thừa kế
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
newObject = Object.create(oldObject);
Có vẻ OK với tôi, nhưng làm sao nó khác với cách tiếp cận simple inheritance John Resig không?
Về cơ bản nó đi xuống
newObject = Object.create(oldObject);
so
newObject = Object.extend();
Và Tôi quan tâm đến lý thuyết. Thực hiện khôn ngoan có vẻ không có nhiều sự khác biệt.
Tôi cũng thích kỹ thuật Object.create(). Tôi thảo luận về nó trên blog của tôi: http://ncombo.wordpress.com/2013/07/11/javascript-inheritance-done-right/ – Jon