如何使用Kotlin匿名类作为本机JavaScript函数的参数?

如何使用Kotlin匿名类作为本机JavaScript函数的参数?,javascript,interop,kotlin,Javascript,Interop,Kotlin,我正在为ThreeJS类设置互操作层,该类的构造函数接收一个用于设置属性的对象 //PointCloudMaterial.js THREE.PointCloudMaterial = function ( parameters ) { THREE.Material.call( this ); this.color = new THREE.Color( 0xffffff ); this.map = null; this.size = 1; this.s

我正在为ThreeJS类设置互操作层,该类的构造函数接收一个用于设置属性的对象

//PointCloudMaterial.js    
THREE.PointCloudMaterial = function ( parameters ) {
    THREE.Material.call( this );
    this.color = new THREE.Color( 0xffffff );
    this.map = null;
    this.size = 1;
    this.sizeAttenuation = true;
    this.vertexColors = THREE.NoColors;
    this.fog = true;
    this.setValues( parameters );
};
下面是我希望能够在Kotlin做的事情,是否有可能以某种方式使用异常对象?我最初想创建一个与可能的周长相等的对象,问题是它会覆盖当前值,这不是我想要的

//Interop Layer
native("THREE.PointCloudMaterial")
public class PointCloudMaterial(parameters: object) { } //This doesn't compile "Type Expected"

//Example usage
var sizeObject = object {
     var size: Double = size
}
PointCloudMaterial(sizeObject);

类型安全解决方案可能如下所示:

native 
val <T> undefined: T = noImpl

class PointCloudMaterialParameters (
   val color: Int = undefined,
   val opacity: Double = undefined,
   //val map: THREE.Texture = undefined,
   val size: Double = undefined,
   //val blending: THREE.NormalBlending = undefined,
   val depthTest: Boolean = undefined,
   val depthWrite: Boolean = undefined,
   val vertexColors: Boolean = undefined,
   val fog: Boolean = undefined
)

fun main(args : Array<String>) {
  println(PointCloudMaterialParameters(size = 2.0))
}

native("THREE.PointCloudMaterial")
public class PointCloudMaterial(parameters: PointCloudMaterialParameters)

//Example usage
PointCloudMaterial(PointCloudMaterialParameters(size = 2.0))

另外,我们将在将来尝试简化这种情况。

第一种不是真正的类型安全的,因为它允许构造具有未定义非空值的PointCloudMaterialParameters。在这种情况下,我相信指向PointCloudMaterialParameters的所有参数都应该可以为null。但是,将它们标记为null也是不正确的,因为Kotlin静态分析器会将它们都视为具有值,这意味着?。和:?接线员不能工作。
native("THREE.PointCloudMaterial")
public class PointCloudMaterial(parameters: Any)

//Example usage
PointCloudMaterial(object { val size = 2.0 })