0
나는 밑줄과 Mongodb를 사용하여 Javascript에서 Rails ActiveRecord의 유사한 버전을 빌드하려고합니다. 새로 생성 된 객체가 클래스 생성자로부터 그의 프로토 타입을 상속받을 수있는 방법에 관해서는 머리를 감쌀 수없는 무언가가 있습니다. 어쩌면 나는 나의 점을 설명하는 경우가 쉬울 것 :자바 스크립트 생성자 프로토 타입
var root = this;
var Database = root.Database = {};
// Require Underscore, if we're on the server, and it's not already present.
var _ = root._;
if (!_ && (typeof require !== 'undefined')) _ = require('./underscore');
Database.ActiveRecord = function(attributes){
attributes || (attributes = {});
this.attributes = {};
};
_.extend(Database.ActiveRecord.prototype, {
idAttribute: '_id',
test : 1,
});
var Client = Database.ActiveRecord;
var one = new Client();
console.log(one.prototype);
개체 하나의 프로토 타입이 Database.ActiveRecord.prototype을 상속하지 않습니다. 무엇이 문제일까요?
이것은 서버 측 내용입니다. 그것을 지정 했어야합니다. – mabounassif
당신은 실제로 옳습니다, 제가 틀린 프로토 타입이라고 부르는 방식입니다. 속성이 있습니다. – mabounassif