### Full postMessage Example Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/3-frames-and-windows/03-cross-window-communication/article.md A complete example demonstrating cross-window communication using postMessage. It includes sending a message from one window and receiving and responding to it in another. ```html ``` -------------------------------- ### Export a function from a module Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/1-js/13-modules/01-modules-intro/article.md Use the `export` keyword to make functions, variables, or classes available for import by other modules. This example exports a `sayHi` function. ```javascript // 📁 sayHi.js export function sayHi(user) { alert(`Hello, ${user}!`); } ``` -------------------------------- ### Convert Canvas to Blob with Async/Await Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/4-binary/03-blob/article.md An alternative to using callbacks for `toBlob`, this snippet demonstrates how to use `async/await` with a Promise to get a Blob from a canvas. ```javascript let blob = await new Promise(resolve => canvasElem.toBlob(resolve, 'image/png')); ``` -------------------------------- ### Test Notification Display in JavaScript Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/2-ui/1-document/08-styles-and-classes/2-create-notification/source.view/index.html Demonstrates how to repeatedly show a notification every 2 seconds using setInterval. This example tests the functionality of the showNotification function with dynamic content. ```javascript let i = 1; setInterval(() => { showNotification({ top: 10, right: 10, html: 'Hello ' + i++, className: "welcome" }); }, 2000); ``` -------------------------------- ### 使用 substr 获取子字符串 Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/1-js/05-data-types/03-string/article.md substr 方法返回从 start 索引开始,长度为 length 的字符串部分。第一个参数可以为负数,表示从字符串末尾开始计算。 ```javascript let str = "st*!*ring*/!*ify"; alert( str.substr(2, 4) ); // 'ring' ``` ```javascript let str = "strin*!*gi*/!*fy"; alert( str.substr(-4, 2) ); // 'gi' ``` -------------------------------- ### Accessing internal properties Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/1-js/99-js-misc/01-proxy/article.md Demonstrates direct access to properties starting with an underscore, which are conventionally considered internal. ```javascript let user = { name: "John", _password: "secret" }; alert(user._password); // secret ``` -------------------------------- ### Object to String Conversion Example Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/1-js/04-object-basics/09-object-toprimitive/article.md Illustrates how an object is converted to a primitive string during string concatenation. The toString method returns '2', which is then concatenated with the number 2. ```javascript let obj = { toString() { return "2"; } }; alert(obj + 2); // 22 ("2" + 2) is converted to the primitive string => concatenation ``` -------------------------------- ### Sending a Message to Any Origin Source: https://github.com/javascript-tutorial/zh.javascript.info/blob/master/3-frames-and-windows/03-cross-window-communication/article.md This example sends a message to an iframe without checking its origin. The targetOrigin is set to '*', meaning any window can receive the message. ```html