0

I have a class / function called MyApp and have some special attributes init for example this.memory and this.userMedia to access these functions within my own app

I don't know if this copies the function or just uses the reference for the function? is this allowed or does it have some kind memory issue?

function MyApp(name) {
    this.name = name;
    // special attributes
    this.memory = window.localStorage;
    this.userMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
}
webmaster
  • 1,960
  • 24
  • 29

2 Answers2

1

I don't know if this copies the function or just uses the reference for the function?

window.localStorage is no function but an object. In JavaScript, objects are passed by reference. That means you're just creating an alias for that objects. I see no problems by doing it this way.

SVSchmidt
  • 6,269
  • 2
  • 26
  • 37
0

That is a constructor function and it is not "special attribute", but property. Everything other than that is absolutely fine.

That is, you are creating name property which takes the argument of name. And you assign memory the reference of localStorage and you are setting userMedia to whichever is available. And I see no harm in it.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95