Skip to content

Instantly share code, notes, and snippets.

@Diullei
Created January 22, 2012 16:21
Show Gist options
  • Select an option

  • Save Diullei/1657570 to your computer and use it in GitHub Desktop.

Select an option

Save Diullei/1657570 to your computer and use it in GitHub Desktop.
// Crio um objeto com o campo _num.
function MyObj(){
this._num = 0;
}
// Adicionamos uma função recursiva para incrementar o valor de _num até que ele seja maior ou igual a 10.
MyObj.prototype.Inc = function(){
console.log(this._num);
this._num++;
if(this._num >= 10)
return;
// chamada recursiva da mesma função
this.Inc();
}
// Instancio um novo objeto
var obj = new MyObj();
// invoco a chamada do método recursivo
obj.Inc();
//=> Como resultado desta função serão logados os números de 0 a 10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment