I have a function that looks like the function below. It takes an object called
link, calls getAdminParams and then uses the return values of that call to
change properties in the link object:
function checkParams(link: Link) {
var rtn : IAdminParams = null,
table = null;
if (link.Action === "Create") {
if (link.Params == null) {
rtn = getAdminParams(link.Entity);
if (rtn.Success) {
link.Url = link.Href + rtn.Param;
table = rtn.Table;
} else {
link.$Link.prop('disabled', false);
return;
}
} else {
link.Url = link.Href + link.Params;
table = link.Entity;
}
} else {
link.Url = link.Href;
}
}
I am calling the function as below.
function adminDialog($link: JQuery) {
var link = new Link($link);
checkParams(link);
doDialogAjax(link);
}
When I pass the value of link to the checkParams(link) will it be passed by
reference? In other words will the changes I make in the checkParams(link: Link)
function be available to the link object so they can be used in the doDialogAjax
function?
Yes, and no.
No.
Yes.
The variable is not passed by reference. It’s passed by value, but the value is a reference.
If the variable was passed by reference, the function could change the variable. That doesn’t happen:
Demo: http://jsfiddle.net/sCJHu/
If the variable was passed by reference,
bwould be replaced by the new object create in the function, andb.valuewould be1.