performance - JavaScript Does memory leak happens every time function is called -


currently attending javascript training trainer told every function write constructor , every time call new object created.

consider following code,

function test(){   console.log("test"); }  test(); test(); 

so every time call test function, create new object every time?

update

according him following code not result in memory leak

function test(name){     this.name = name; }  var 1 = new test("nicholas"); 

and following code allocate object , result in memory leak

function createtest(name){     var t = new object();     t.name = name;     return t; }  var 2 = createtest("nicholas"); 

every function write constructor

no not true.

every time call new object created.

if calling constructor using new yes new object craeted. otherwise not true.

and yes there no memory leak happens when create object or when call function.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -