You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/javascript-interoperability/index.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,40 @@ In a few documentation examples, JS interop is used to mutate an element *purely
62
62
63
63
For more information, see <xref:blazor/js-interop/call-javascript-from-dotnet#capture-references-to-elements>.
64
64
65
+
## JavaScript class with a field of type function
66
+
67
+
A JavaScript class with a field of type function is ***not*** supported by Blazor JS interop. Use Javascript functions in classes.
68
+
69
+
<spanaria-hidden="true">❌</span><spanclass="visually-hidden">Unsupported:</span> `GreetingHelpers.sayHello` in the following class as a field of type function isn't discovered by Blazor's JS interop and can't be executed from C# code:
70
+
71
+
```javascript
72
+
exportclassGreetingHelpers {
73
+
sayHello=function() {
74
+
...
75
+
}
76
+
}
77
+
```
78
+
79
+
<spanaria-hidden="true">✔️</span><spanclass="visually-hidden">Supported:</span> `GreetingHelpers.sayHello` in the following class as a function is supported:
80
+
81
+
```javascript
82
+
exportclassGreetingHelpers {
83
+
sayHello() {
84
+
...
85
+
}
86
+
}
87
+
```
88
+
89
+
Arrow functions are also supported:
90
+
91
+
```javascript
92
+
exportclassGreetingHelpers {
93
+
sayHello= () => {
94
+
...
95
+
}
96
+
}
97
+
```
98
+
65
99
## Avoid inline event handlers
66
100
67
101
A JavaScript function can be invoked directly from an inline event handler. In the following example, `alertUser` is a JavaScript function called when the button is selected by the user:
0 commit comments