作者oopFoo (3d)
看板Soft_Job
标题Re: [心得] Webgl+Js的Spa
时间Sun Mar 31 22:50:11 2019
之前说typedarray不好用,因为subarray出来的view其实很昂贵,整个记忆体使用量爆增。但因
http://glmatrix.net/ 的library的api需要这样,我又不想重写。
现在有个solution分享一下。我加了类似下面这样的程式。
Object.defineProperties(Vertex.prototype, {
0: { get: function() {return Vertex.position[this.posOffset];},
set: function(value) {Vertex.position[this.posOffset] = value;} },
1: { get: function() {return Vertex.position[this.posOffset+1];},
set: function(value) {Vertex.position[this.posOfset+1] = value;} },
2: { get: function() {return Vertex.position[this.posOffset+2];},
set: function(value) {Vertex.position[this.posOffset+2] = value;} }
});
是的,Javascript可以有数字的member。但只能vertex[0]这样access,不能vertex.1。
glmatrix的api,vec3使用array[0], [1],[2]。所以我就define, 0, 1, 2的member。这样就不用subarray出一个float32array(3)的东东。
这算是duck typing, 比class, inheritance更接近Alan Kay,oop之父,定义的oop
http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay_oop_en
Dr. Alan Kay在这email里把OOP定义清楚。我们所了解的OOP是从Simula 67来的,因c++而普及,其实并不是Alan Kay的OOP。
他的定义是写在最後
"OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them."
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.227.164.111
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Soft_Job/M.1554043816.A.1AF.html
1F:推 dreamnook: 04/01 09:23