jweinst1
5/22/2016 - 10:09 PM

jsgenerator.js

//js closure

//simple number sequence generator
function naturalgen(){
	var num = 0;
	return function(){
		num += 1;
		return num;
	};
}

//sample string generator

function stringgen(string){
	return function(){
		string += string;
		return string;
	};
}
/*   var f = stringgen("hello")
   f
=> [Function]
   f()
=> 'hellohello'
   f()
=> 'hellohellohellohello'
   f()
=> 'hellohellohellohellohellohellohellohello'
   f()*/