I have the following javascript code:
var oLink = {
title: $link.attr('title') || '',
row: $link.attr('data-row') || '',
$modal: ''
}
I now call a function like this:
oLink.$modal = accessModalOpen(oLink, content);
Do I need to return oLink.$modal or could I just set it inside accessModalOpen? In other words is the parameter oLink passed as a reference in javascript?
Update:
Added $modal to the oLink declaration
Yes. Within your function, you will have a reference to the same object, not a copy of the object, so yes you can update, add and delete object properties within your function.
Note though that it’s not “pass by reference” in the sense that some languages have it. The variable outside the function and the parameter used inside the function will both refer to the same object, which is why you can change its properties, but if you assign the function parameter to some other object that doesn’t affect the variable outside the function which will continue to refer to the original object.