I'm looking for a way to add a javascript object to the DOM without redefining the object.
I have created a function that puts all object methods into a new object, redefines the object as a new DOM element, and puts all the objects back onto it but this is not exactly what I want. I need the object to be updated without using any return statements.
I have an example here: http://jsfiddle.net/y56wS/
function addToDOM(obj) {
temp = {};
for (p in obj) {
temp[p] = obj[p];
}
obj = document.createElement('prop');
document.body.appendChild(obj);
for (p in temp) {
obj[p] = temp[p];
}
return obj;
}
var obj = {var1:123};
obj = addToDOM(obj);
The resulting code template should be something like this:
function addToDOM(obj) {
//Code for method
//No return statement
}
var obj = {var1:123};
//No obj=
addToDOM(obj);
To accomplish this, there really has to be no obj = within the addToDOM function so that it is never redefined and there is no need for a return statement. Is there a way to simply extend the javascript object onto the DOM?
obj = addToDOM(obj)after definingobj = {}. I just want to make it so I can includeaddToDOM(obj)as part of the polyfill and to do that I have to add it to a DOM element without redefining it. Was that more clear?