Witam,
Dla poniższego kodu JS, gdy tworzę serie obiektów :
new Marker();
new Marker(51.88, 19.17, 'Krakow')
new Marker(51.88, 19.17, 'Krakow', 'img/point.png', false);
dostaje komunikaty:
Dzyn3
Dzyn3
Dzyn3
Zawsze wywoluje sie najnizej polozony konstruktor.
Ma ktos pomysl, jak wywolac odpowiednie konstruktory??
var Marker = (function () {
var lat;
var lng;
var title;
var icon;
var animate;
function Marker() {
alert('Dzyn1');
}
function Marker(lat, lng, title) {
alert('Dzyn2');
this.lat = lat;
this.lng = lng;
this.title = title;
this.icon = 'img/marker.png';
this.animate = false;
};
function Marker(lat, lng, title, icon, animate) {
alert('Dzyn3');
this.lat = lat;
this.lng = lng;
this.title = title;
this.icon = icon;
this.animate = animate;
};
Marker.prototype.setLat = function(lat) {
this.lat = lat;
};
Marker.prototype.getLat = function() {
return this.lat;
};
Marker.prototype.setLng = function(lng) {
this.lng = lng;
};
Marker.prototype.getLng = function() {
return this.lng;
};
Marker.prototype.setTitle = function(title) {
this.title = title;
};
Marker.prototype.getTitle = function() {
return this.title;
};
Marker.prototype.setIcon = function(icon) {
this.icon = icon;
};
Marker.prototype.getIcon = function() {
return this.icon;
};
Marker.prototype.setAnimate = function(isAnimate) {
this.animate = isAnimate;
};
Marker.prototype.getAnimate = function() {
return this.animate;
};
Marker.prototype.toString = function() {
return 'lat = ' + this.lat + ', lng = ' + this.lng + ', title = ' + this.title + ', icon = ' + this.icon + ', isAnimate = ' + this.animate;
};
return Marker;
}());