Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34371
| From | Jan Bruns <ebay@abnuto.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Object.create(canvas.getContext()) |
| Date | 2017-11-19 21:39 +0000 |
| Organization | MB-NET.NET for Open-News-Network e.V. |
| Message-ID | <oustnb$gbb$1@gwaiyur.mb-net.net> (permalink) |
| References | (1 earlier) <5326256.lOV4Wx5bFT@PointedEars.de> <ouel6d$nvu$1@gwaiyur.mb-net.net> <1754058.usQuhbGJ8B@PointedEars.de> <oungju$hmt$1@gwaiyur.mb-net.net> <10957516.O9o76ZdvQC@PointedEars.de> |
Thomas 'PointedEars' Lahn:
> Jan Bruns wrote:
>> this.define_method = function(nam,cobj,cfun){
>>
>> this[nam] = function() { return cfun.apply(cobj,arguments); };
>>
>> };
>>
>> this.inherit_methods = function(o) {
>>
>> for (var i in o) { if (typeof(o[i])=="function") {
>>
>> this.define_method(i,o,o[i]);
>>
>> };};};
>>
>>
>> this.inherit_methods(gl);
>>
>> Looks much more human readable to me.
> YMMV. But your code is also much more error-prone
Well, it comes with useful flexibility.
For example, some webgl extensions come with additional methods that have
been adopted to webgl2.
With webgl1 they're used like
var e = gl.getExtension(some_name);
e.someMethod_suffix(); // call some extension's method
whereas in webgl2, they've become part of the API:
gl.someMethod();
So it'll simply be best to load the extension with:
var e = gl.getExtension(some_name);
gl.define_method("someMethod",e,e.someMethod_suffix);
> (and lacks code style).
Style? My newsreader is broken (I think). Somehow linebreaks get lost
somewhere, probably to get some format-flowed styling.
> For example, there is a reason why I enclosed the host object property
> access in a “try” block.
What is that reason? Does "typeof" throw on any enumerated property
anywhere?
Gruss
Jan Bruns
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Object.create(canvas.getContext()) Jan Bruns <ebay@abnuto.de> - 2017-11-12 10:09 +0000
Re: Object.create(canvas.getContext()) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-12 17:42 +0100
Re: Object.create(canvas.getContext()) Jan Bruns <ebay@abnuto.de> - 2017-11-14 11:48 +0000
Re: Object.create(canvas.getContext()) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-15 02:32 +0100
Re: Object.create(canvas.getContext()) Jan Bruns <ebay@abnuto.de> - 2017-11-17 20:25 +0000
Re: Object.create(canvas.getContext()) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-19 05:48 +0100
Re: Object.create(canvas.getContext()) Jan Bruns <ebay@abnuto.de> - 2017-11-19 21:39 +0000
Re: Object.create(canvas.getContext()) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-19 23:34 +0100
Re: Object.create(canvas.getContext()) Jan Bruns <ebay@abnuto.de> - 2017-11-20 14:47 +0000
Re: Object.create(canvas.getContext()) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-21 04:07 +0100
Re: Object.create(canvas.getContext()) Jan Bruns <ebay@abnuto.de> - 2017-11-21 16:23 +0000
Re: Object.create(canvas.getContext()) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-22 04:12 +0100
Re: Object.create(canvas.getContext()) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-12 18:45 +0100
csiph-web