This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import WebKit | |
class ViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler { | |
var webView: WKWebView! | |
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { | |
print("Hello world") | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadScript(src, { scriptId = '', insertBeforeAllTags = false } = {}) { | |
return new Promise((resolve, reject) => { | |
let script = document.createElement('script'); | |
script.id = scriptId; | |
script.onload = resolve; | |
script.onerror = event => { | |
reject(new ExternalScriptError(event.target.src)); | |
}; | |
script.src = src; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const videoSegments = new WeakMap() | |
let options = { id: "1234", timeStart: 1653831957378, size: 10000 } | |
const segment = { data: new Uint8Array(200) } | |
videoSegments.set(options, segment) | |
console.warn(videoSegments.get(options)) // { data: new Uint8Array(200) } | |
options = null | |
console.warn(videoSegments.has(options)) // false, the `options` key object is deleted from the WeakMap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const results = await getPosts().catch((err) => { | |
return { | |
type: "error", | |
message: err.message | |
} | |
}); | |
console.warn(results) // { type: "error", message: "cannot get posts from this endpoint" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contacts = [ | |
{ address: "20B Rue Lafayette", name: "work" }, | |
{ address: "90B Rue laffite", name: "bar" } | |
]; | |
const contact = contacts.find(contact => contact.name === "home") | |
console.warn(contact) // undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contactInfos = { address: "20B Rue Lafayette" }; | |
function setAddress(infos) { | |
infos.address = "90B Rue laffite"; | |
} | |
console.warn(contactInfos); // { address: "20B Rue Lafayette" } | |
setAddress(contactInfos); | |
console.warn(contactInfos); // { address: "90B Rue laffite" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.warn(true && "1") // "1" | |
console.warn(false && "1") // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moreInfos = { info: "Please go to the desk." } | |
return { | |
address: "20B Rue Lafayette", | |
postcode: "75009", | |
...(moreInfos !== undefined && { moreInfos }) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contactInfos = { address: "20B Rue Lafayette", addressNumber: 0 }; | |
console.warn(contactInfos.addressNumber || undefined) // undefined | |
console.warn(contactInfos.addressNumber ?? undefined) // 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contactInfos = { address: "20B Rue Lafayette" }; | |
console.warn(contactInfos.user?.phoneNumber ?? "") | |
// "" |
NewerOlder