title: Javascript polymorphism without OOP classes
body: <p>In JS or OOP language the polymorhpism is created by making different types.</p>
  
  <p>For example:</p>
  
  <pre><code>class Field {...}
  
  class DropdownField extends Field {
    getValue() { 
       //implementation ....
    }
  }
  </code></pre>
  
  <p>Imagine I have library forms.js with some methods:</p>
  
  <pre><code>class Forms {
      getFieldsValues() {
        let values = [];
        for (let f of this.fields) {
            values.push(f.getValue());
        }
        return values;
      }
  }
  </code></pre>
  
  <p>This gets all field values. Notice the library doesnt care what field it is.</p>
  
  <p>This way developer A created the library and developer B can make new fields: AutocompleterField.</p>
  
  <p>He can add methods in AutocompleterField withouth changing the library code (Forms.js) .</p>
  
  <p>If I use functional programming method in JS, how can I achieve this?</p>
  
  <p>If I dont have methods in object i can use case statements but this violates the principle. Similar to this:</p>
  
  <pre><code>if (field.type == 'DropdownField')...
  else if (field.type == 'Autocompleter')..
  </code></pre>
  
  <p>If developer B add new type he should change the library code.</p>
  
  <p>So is there any good way to solve the issue in javascript without using object oriented programming. </p>
  
  <p>I know Js isnt exactly OOP nor FP but anyway.</p>
  
  <p>Thanks</p>