Pregunta de entrevista de Goldman Sachs

Explain how to implement encapsulation in Javascript

Respuesta de la entrevista

Anónimo

21 oct 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'