mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-27 10:22:35 +02:00
Use proper prototypal inheritance and less dynamic new
This commit is contained in:
+2
-9
@@ -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) {
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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: [],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user