forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwiftClass.swift
More file actions
37 lines (29 loc) · 894 Bytes
/
SwiftClass.swift
File metadata and controls
37 lines (29 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@JS class Greeter {
@JS var name: String
@JS init(name: String) {
self.name = name
}
@JS func greet() -> String {
return "Hello, " + self.name + "!"
}
@JS func changeName(name: String) {
self.name = name
}
}
extension Greeter {
@JS func greetEnthusiastically() -> String {
return "Hey, " + self.name + "!!!"
}
@JS var nameCount: Int { name.count }
@JS static func greetAnonymously() -> String {
return "Hello."
}
@JS static var defaultGreeting: String { "Hello, world!" }
}
@JS func takeGreeter(greeter: Greeter) {
print(greeter.greet())
}
@JS public class PublicGreeter {}
@JS package class PackageGreeter {}
@JSFunction func jsRoundTripGreeter(greeter: Greeter) throws(JSException) -> Greeter
@JSFunction func jsRoundTripOptionalGreeter(greeter: Greeter?) throws(JSException) -> Greeter?