Appframe Knowledge Base

1 hits

How to extend a JavaScript object

/* Calling af.common.extend will take the first object, and merge any subsequent objects into the first one,
   overwriting any previous values having the same key. The function returns the modified first parameter. */

var vMyObject = { myItem: true, secondItem: 1 };

af.common.extend(vMyObject, { secondItem: 2, newItem: "Hi" });

// vMyObject is now: { myItem: true, secondItem: 2, newItem: "Hi" }

common web · Perma link post comment Posted by: Jan Henrik H. Meling (05-okt-2012)