, - - , , , , - . , ... JSON $.extend ?
"" - , . :
function namespace(str, scope){
scope = scope || window;
var parts = str.split('.');
while(parts.length)
scope = scope[parts.shift()];
return scope;
}
Foo = {};
Foo.Bar = function(conf){
$.extend(this, conf);
};
var json = {
type: 'Foo.Bar',
var1: 1,
var2: 2,
var3: 3
};
var obj = new (namespace(json.type))(json);
console.log(obj, obj instanceof Foo.Bar);
... :
$.getJSON("foo.json").done(function(data, textStatus, xhr){
data.objects = $.map(data.objects, function(obj){
return new (namespace(obj.type))(obj);
});
});