Created
January 22, 2012 16:21
-
-
Save Diullei/1657570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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