Search code examples
javascripthtmlclassobjectfactory-pattern

Pattern Factory return [object Object] in my HTML


When I use my pattern factory for my slider, it returns me "[object Object]" instead of having HTML. Class code

HTML develop tools

Do you have any idea what could happen?

Thank you so much :)


Solution

  • Contructor cann't return anything, but the object he creates and returns internally. To avoid this behavior use something like.

       class MediaFactory {
          getContent(data, layout) {
             // your code goes here
          }
    
       }
    

    and usage will be

    ....innerHtml = new MediaFactory().getContent(article, 'slider')