Use proper prototypal inheritance and less dynamic new

This commit is contained in:
John Firebaugh
2013-01-11 15:17:21 -08:00
parent f2c6227cb3
commit d74bf1e39a
5 changed files with 35 additions and 25 deletions
+2 -9
View File
@@ -77,15 +77,8 @@ iD.Connection = function() {
delete o.lat;
}
o.id = iD.Entity.id.fromOSM(o.type, o.id);
switch (o.type) {
case 'node':
o._poi = !refNodes[o.id];
return iD.Node(o);
case 'way':
return iD.Way(o);
case 'relation':
return iD.Relation(o);
}
if (o.type === 'node') o._poi = !refNodes[o.id];
return new iD.Entity[o.type](o);
}
function parse(dom) {
-13
View File
@@ -109,16 +109,3 @@ iD.Entity.prototype = {
return n.length === 0 ? 'unknown' : n.join('; ');
}
};
iD.Entity.extend = function(properties) {
var Subclass = function() {
if (this instanceof Subclass) return;
return (new Subclass()).initialize(arguments);
};
Subclass.prototype = new iD.Entity();
_.extend(Subclass.prototype, properties);
iD.Entity[properties.type] = Subclass;
return Subclass;
};
+11 -1
View File
@@ -1,4 +1,14 @@
iD.Node = iD.Entity.extend({
iD.Node = iD.Entity.node = function iD_Node() {
if (!(this instanceof iD_Node)) {
return (new iD_Node()).initialize(arguments);
} else if (arguments.length) {
this.initialize(arguments);
}
};
iD.Node.prototype = Object.create(iD.Entity.prototype);
_.extend(iD.Node.prototype, {
type: "node",
extent: function() {
+11 -1
View File
@@ -1,4 +1,14 @@
iD.Relation = iD.Entity.extend({
iD.Relation = iD.Entity.relation = function iD_Relation() {
if (!(this instanceof iD_Relation)) {
return (new iD_Relation()).initialize(arguments);
} else if (arguments.length) {
this.initialize(arguments);
}
};
iD.Relation.prototype = Object.create(iD.Entity.prototype);
_.extend(iD.Relation.prototype, {
type: "relation",
members: [],
+11 -1
View File
@@ -1,4 +1,14 @@
iD.Way = iD.Entity.extend({
iD.Way = iD.Entity.way = function iD_Way() {
if (!(this instanceof iD_Way)) {
return (new iD_Way()).initialize(arguments);
} else if (arguments.length) {
this.initialize(arguments);
}
};
iD.Way.prototype = Object.create(iD.Entity.prototype);
_.extend(iD.Way.prototype, {
type: "way",
nodes: [],