Strange behaviour with Fable to Javascript Bindings

Viewed 18

I have the following javascript

//file1.js

class MyClass {
  constructor(name) {
    this.Name = name;
  }
}

function callMeBack(callback) {
  let v = new MyClass("MyName")
  callback(v)
}

export { callMeBack };

and the relative Fable JS bindings

//Bindings.fs

type I =
    abstract callMeBack<'t> : callback:('t -> unit) -> unit


module Binding = 
    [<ImportAll("./file1.js")>]
    let mylib: I = jsNative

Then I use the bindings in an application, calling javascript twice but with different F# types (class and record)

type MyClass(name: string) = 
    let mutable _name: string = name
    member __.Name with get() = _name and set v = _name <- v

type MyRecord = {
    Name: string
} 

let fClass() = 
    Binding.mylib.callMeBack(fun (v:MyClass) ->
        let name = v.Name
        printf "%s" v.Name)

let fRecord() = 
    Binding.mylib.callMeBack(fun (v:MyRecord) ->
        let name = v.Name
        printf "%s" v.Name)

Problems:

  • Different results between class and record
  • With class the result is wrong

enter image description here enter image description here

enter image description here enter image description here

Questions

1. Why this happens?

2. How to obtain the correct result with class type?

0 Answers
Related