Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

OOP: duck-typing III • Let’s Exciting JavaScript - Part I

8,267 views

Published on

OOP: duck-typing III
• Let’s implement a counter from 1 to 5:
var it = {
value: 1, limit: 5,
hasNext: function(){ return this.value <= this.limit; },
next: function(){ return this.value++; }
};
// consumer
function consume(it){
while(it.hasNext()){ alert(it.next()); }
}



31

Published in: Technology

×