0

I want a function that modifies a variable e.g.:

private _buildUrlCategories(url: string) {
  url += ";categories=" + this.findForm.value.categories;
}

private _buildUrl() {
  let url = "/#/find";
  this._buildUrlCategories(url); //now url should be bigger
}

If it can't be done then obviously I can just return the url and do url += this._buildUrlCategories(url).

Is this possible? Is this a technique that has a name?

jacefarm
  • 6,747
  • 6
  • 36
  • 46
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
  • 1
    or, see http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language. –  Jan 05 '17 at 06:52

1 Answers1

2

No, it can't be done.

From the TypeScript specification:

TypeScript is a syntactic sugar for JavaScript. TypeScript syntax is a superset of ECMAScript 2015 (ES2015) syntax. Every JavaScript program is also a TypeScript program.

TypeScript is a superset of JavaScript and in JavaScript, arguments can not be passed by reference (well, except objects).

Community
  • 1
  • 1
Fabian Lauer
  • 8,891
  • 4
  • 26
  • 35