Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34356
| Path | csiph.com!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.214.226.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Object.create(canvas.getContext()) |
| Date | Wed, 15 Nov 2017 02:32:10 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 98 |
| Message-ID | <1754058.usQuhbGJ8B@PointedEars.de> (permalink) |
| References | <ou96ju$mvd$1@gwaiyur.mb-net.net> <5326256.lOV4Wx5bFT@PointedEars.de> <ouel6d$nvu$1@gwaiyur.mb-net.net> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| Injection-Info | gwaiyur.mb-net.net; posting-host="214.226.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch:178.197.226.214"; logging-data="19495"; mail-complaints-to="abuse@open-news-network.org" |
| User-Agent | KNode/4.14.2 |
| Cancel-Lock | sha1:l2dlSPf2u1s3oHQvnuOGj+Qv0P8= |
| X-User-ID | U2FsdGVkX1+h0E+eg48x2t4QYyi/6XnIfqO3KOwIMJYuWSlXeMYrGQ== |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Xref | csiph.com comp.lang.javascript:34356 |
Show key headers only | View raw
Jan Bruns wrote:
> Thomas 'PointedEars' Lahn:
>> […] this is particulary true of host objects as this one. If subclassing
>> does not work either (or cannot be assumed to be available), create a
>> wrapper object.
>
> That's what I wanted to avoid.
>
> Open GL, GL ES, and webgl are all APIs that hide obejct oriented
> programming aspects by some state mechanism. For example, to change some
> object's property often means to first set the object reference to some
> "current object" state using some API method, to finally change the
> property of that "current object" using some other API method.
>
> This is beacause initial OpenGL was focused on plain C usage, I guess.
WebGL is an *object-oriented* API based on OpenGL ES 2.0, so I do not see
your point.
> Wrapping all the webgl methods explicitly just to get some functionality
> that the prototype chain and the API's host code could do doesn't sound
> very attractive either, so I'll decide to put the burden to distungish
> native API calls from helper API calls on some higher level helper API.
Your choice. I see that subclassing does not work in this case.
But it appears to be rather easy to create such a wrapper, at least in
Chromium 57:
var my = (function () {
var canvas = document.createElement("canvas");
var context = canvas.getContext("webgl");
var proto = Object.getPrototypeOf(context);
function WebGLWrapper (context)
{
this.context = context;
}
/* Wrap built-in methods */
Object.assign(WebGLWrapper.prototype, (function () {
var wrappedMethods = Object.create(null);
// Object.keys(proto).forEach(function (key) {
Object.keys(proto).forEach((key) => {
try
{
if (typeof proto[key] == "function")
{
wrappedMethods[key] = (function (freeKey) {
return function (...args) {
// this.context[freeKey].apply(this.context, arguments);
return this.context[freeKey](...args);
};
}(key));
}
}
catch (e) {}
});
return wrappedMethods;
}()));
Object.assign(WebGLWrapper.prototype, {
/* custom methods */
});
return {
/** @memberOf my */
WebGLWrapper: WebGLWrapper
};
}());
// gl = new my.WebGLWrapper(gl);
Barely tested.
>> If available, you can use “Proxy” (ECMAScript 2015+) or
>> “__noSuchMethod__” (Mozilla JavaScript 43+ only, obsolete) to implement
>> seamless access.
>
> Didn't know about that, but currently looks like much of browser
> specifics
WebGL is browser-specific. “Proxy” is not, in general. However, Internet
Explorer supports WebGL, but its JScript version does not implement either
“Proxy” or “__noSuchMethod__”, which might be a showstopper for that
approach.
> that don't have anything to do with webgl.
Yes, it is a general approach. Your point being?
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
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