Domanda di colloquio di Goldman Sachs

Explain how to implement encapsulation in Javascript

Risposta di colloquio

Anonimo

21 ott 2015

function test(){ var count = 0; var inc = function(){ count+=1; } var getcount = function(){ return count; } } var t = test(); alert[count); //Count not defined at global scope alert[t.getcount()); //alerts '0' t.inc(); alert[t.getcount()); //alerts '1'