can*_*sin 0 javascript arrays floating-point subclass coffeescript
我正在用CoffeScript编写一个库(所以JS),这是一个繁重的数学..我真的需要使用类型数组(Float64Array)和它们提供的所有性能.
那么扩展类型化数组功能的最佳方法是什么?
目前我正在做功能:
Vector =
create: (ag...) ->
CGE2Point.create ag...
dot: (i,j) ->
i[0]*j[0] + i[1]*j[1]
add: (i,j) ->
@.create i[0]+j[0], i[1]+j[1]
sub: (i,j) ->
@.create i[0]-j[0], i[1]-j[1]
mul: (s,v) ->
@.create s * v[0], s * v[1]
div: (s,v) ->
@.create v[0] / s, v[1] / s
Run Code Online (Sandbox Code Playgroud)
但是拥有一个继承自类型化数组的Vector对象会非常好.我知道这个方法:
class Vector extends Float64Array
Run Code Online (Sandbox Code Playgroud)
创建一个没有类型化数组的全部好处的类关于子类化数组的问题,阅读以下文章Dean Edwards建议从iframe获取对象副本,这个其他参考以其他方式做对不起Dean.但是类型化数组没有所有方法.
那么,如何正确(或至少最优雅和最佳)子类化类型化数组?或者我应该写所有类似的功能?