I just started to learn some oop and design patterns so I have this example:
function Img(imgId, imgSrc, imgClass) {
this.imgId = imgId || '';
this.imgSrc = imgSrc || '';
this.imgClass = imgClass;
let elm = document.createElement('img');
elm.setAttribute('id', this.imgId);
elm.setAttribute('src', this.imgSrc);
elm.classList.add(this.imgClass);
var xyz = document.getElementById('xyz');
this.createImage = function() {
xyz.appendChild(elm);
}
}
var flowerImg = new Img('flower', 'http://ift.tt/2sLphk6', 'img').createImage();
var airplane = new Img('airplane', 'http://ift.tt/2sLphk6', 'img img-wide').createImage();
<div action="" id="xyz">
</div>
So if I try to use more than one class as function parameter, I get error.
I am trying to understand what and how to overcome it.
Aucun commentaire:
Enregistrer un commentaire