Factory in Scala & JavaScript