Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/docs/javascript/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export function hello() {
And this F# code:

```fs
open Fable.Core

[<Import("hello", "./hello.js")>]
let hello : unit -> unit = jsNative

Expand Down Expand Up @@ -64,6 +66,8 @@ There are 2 families of imports:
They archieve the same goal, but with a slightly generated code.

```fs
open Fable.Core

[<Import("hello", "./hello.js")>]
let hello : unit -> unit = jsNative

Expand Down Expand Up @@ -93,13 +97,17 @@ Some JavaScript optimizations tools can remove the intermediate variable, but no
When trying to bind a global variable, you can use the `[<Global>]` attribute.

```fs
open Fable.Core

[<Global>]
let console: JS.Console = jsNative
```

If you want to use a different in you F# code, you can use the `name` parameter:

```fs
open Fable.Core

[<Global("console")>]
let logger: JS.Console = jsNative
```
Expand All @@ -112,6 +120,8 @@ This attributes takes two parameters:
- `from`: the path to the JavaScript file / module

```fs
open Fable.Core

[<Import("hello", "./hello.js")>]
let hello : unit -> unit = jsNative
// Generates: import { hello } from "./hello.js";
Expand All @@ -130,6 +140,8 @@ let hello : unit -> unit = jsNative
`ImportAll` is used to import all members from a JavaScript module and use the F# value name as the name of the imported module.

```fs
open Fable.Core

[<ImportAll("./hello.js")>]
let hello : unit -> unit = jsNative
// Generates: import * as hello from "./hello.js";
Expand All @@ -140,6 +152,8 @@ let hello : unit -> unit = jsNative
`ImportMember` is used to import a specific member from a JavaScript module, the name is based on the name of the F# value.

```fs
open Fable.Core

[<ImportMember("./hello.js")>]
let hello : unit -> unit = jsNative
// Generates: import { hello } from "./hello.js";
Expand All @@ -150,6 +164,8 @@ let hello : unit -> unit = jsNative
`ImportDefault` is used to import the default member from a JavaScript module, the name is based on the name of imported module.

```fs
open Fable.Core

[<ImportDefault("./hello.js")>]
let hello : unit -> unit = jsNative
// Generates: import hello from "./hello.js";
Expand Down