Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14141
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Generators |
| Date | 2012-05-24 18:05 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <810dbe89-a99d-465d-af7e-ff012ce978df@googlegroups.com> (permalink) |
| References | <6e3d5089-590b-4894-a582-f0805a3d1b12@googlegroups.com> |
On Thursday, May 24, 2012 7:41:04 PM UTC-5, Michael Haufe (TNO) wrote:
> I'm using JavaScript 1.8.5
>
> I'm attempting to implement the following:
>
> RegExp.prototype.findAll = function(str){
> var m;
> while((m = this.exec(str)))
> yield m;
> }
>
> Generator.prototype.map = function(fn,$this){
> return (fn.apply($this,value) for each(value in this));
> }
>
> Generator.prototype.toArray = function(){
> return [i for each(i in this)];
> }
>
> for use in code similar to the following:
>
> ...
> tokenize: function(src){
> return this.reTokens.findAll(src).map(function(m){
> ...
> return token;
> },this).toArray();
> }
> ...
>
> The problem is that I receive the following error:
>
> "Generator is not defined"
>
> The code is included in the page with the following:
>
> <script type="application/javascript;version=1.8" src="..."></script>
>
> And in the debugger I ca do the following:
>
> var f = this.reTokens.findAll(src);
>
> The debugger tells me that "f" is a Generator object
>
> The following also tells me that there is a Global Generator object:
>
> <https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Generator>
>
> What am I doing wrong?
It looks like I can access the Generator object indirectly only:
(function(){
var Generator = (i for(i in null)).constructor;
Generator.prototype.map = function(fn,$this){
for each(var i in this){
yield fn.apply($this,i)
}
}
Generator.prototype.toArray = function(){
return [i for each(i in this)];
}
})();
But I can't iterate over the Generator instance, hmm...
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Generators "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-05-24 17:41 -0700 Re: Generators "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-05-24 18:05 -0700
csiph-web