javascript - Angular inheritance in factories -


in current project working angular in front first time , having little problem extending "classes" true factories.

case: have 3 types of markers can placed on map. 1. assigned markers. 2. unassigned markers. 3. panned markers.

i have base marker object

engine.factory('marker', ['map','icons', function (map, icons) {   var marker = function marker() {};   marker.prototype.mouseover = function mouseover (e) {   e.target.seticon(this.icons[this.icononhover]);  };   marker.prototype.mouseout = function mouseout (e) {    e.target.seticon(icons[this.icon]);  };  return marker;  }]); 

and trying make panned marker

engine.factory('pannedmarker', ['map', 'marker', 'icons', function (map, marker, icons) {   var pannedmarker = {};  pannedmarker.prototype = new marker();   return function pannedmarker(location, id) {    this.id = id;    this.location = location;    this.icon = 'purple';    this.icononhover = 'purplehover';     l.marker(this.location, {icon: icons.purple}).addto(map.map)    .on('mouseover', this.mouseover)    .on('mouseout', this.mouseout);   }; }]); 

when mouse on over marker error: uncaught typeerror: cannot call method 'call' of undefined

i not @ js prototyping , hope constructed information how implement best practice. cause know not proper way.

var pannedmarker = {}; pannedmarker.prototype = new marker(); 

this doesn't make sense, because object doesn't have prototype property (functions do). after do

return function pannedmarker(location, id) { 

which overrides variable pannedmarker again

here article javascript inheritance, maybe helps: javascript inheritance


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -