const: Eigenschaftszuweisung an Objekt

Beitrag lesen

Mich würde mal interessieren, ob es möglich ist, in Javascript einem Objekt einen Stapel Eigenschaften irgendwie über eine Schleife zuzuweisen, statt jede Zuweisung einzeln zu notieren.

function initShaderProgram ( ) {

  shaderProgram.aVertexPosition = gl.getAttribLocation(shaderProgram, 'aVertexPosition');
  shaderProgram.aVertexNormal = gl.getAttribLocation(shaderProgram, 'aVertexNormal');
  shaderProgram.aVertexColor = gl.getAttribLocation(shaderProgram, 'aVertexColor');
  shaderProgram.aTextureCoord = gl.getAttribLocation(shaderProgram, 'aTextureCoord');
Array("aVertexPosition", "aVertexNormal", "aVertexColor", "aTextureCoord" usw).forEach(function (eigenschaft) {
    shaderProgram[eigenschaft] = gl.getAttribLocation(shaderProgram, eigenschaft)
});