Prototype#

../../_images/bank-style-01.webp

Was ist ein Prototype?

Funktionen eines Objekt-Typs?#

Hier am Beispiel eines Arrays:

var classobj = Array.prototype;
console.log(
  Object.getOwnPropertyNames(classobj).filter(function (x) {
    return typeof classobj[x] === 'function'
  })
);

Ausgabe#

[
  'constructor',    'concat',   'copyWithin',
  'fill',           'find',     'findIndex',
  'lastIndexOf',    'pop',      'push',
  'reverse',        'shift',    'unshift',
  'slice',          'sort',     'splice',
  'includes',       'indexOf',  'join',
  'keys',           'entries',  'values',
  'forEach',        'filter',   'flat',
  'flatMap',        'map',      'every',
  'some',           'reduce',   'reduceRight',
  'toLocaleString', 'toString', 'at'
]

Prototype und eigene Funktionen#

Anwendung des Prototyp-Objekts in selbstdefinierten Objekten:

Beschrieben in Objekt (Person)