// Store data localStorage.setItem("username", "john_doe"); // Retrieve data let username = localStorage.getItem("username"); // Remove data localStorage.removeItem("username");
//store data sessionStorage.setItem("sessionId", "12345"); //get data let sessionId = sessionStorage.getItem("sessionId"); //delete data sessionStorage.removeItem("sessionId");
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d");
let x = 50; // Circle's first pixel in the x axis let y = 50; // Circle's first pixel in the y axis function animate() { ctx.clearRect(0, 0, canvas.width, canvas.height); // Let's erase the last circle ctx.beginPath(); ctx.arc(x, y, 20, 0, Math.PI * 2); // Place a circle in the center ctx.fillStyle = "red"; ctx.fill(); x += 1; // Increment x position by 1 Pixel. y += 1; // Increment y position by 1 Pixel. requestAnimationFrame(animate); // Move on to the next frame and repeat. } animate(); // Drawing and looping the animation.
fetch('https://api.example.com/data') .then(response => response.json()) .then(data =>{ console.log(data); }) .catch(error => { console.error('There was an error!', error); });
fetch('https://api.example.com/data').then(response => { const statusCode = response.status; if (!(statusCode >= 200 && statusCode < 300)) { throw new Error("Network response was not ok"); } return response.json(); }).then(data => { console.log(data); }).catch(error => { console.error('There was a problem with the fetch operation:', error); });
const data = { username: 'john_doe', email: '[email protected]' }; fetch('https://api.example.com/users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('User created:', data); }) .catch(error => { console.error('There was an error!', error); });
// math.js export const add = (a, b) => a + b; export const subtract = (a, b) => a - b;
//Dummy.js const logger = (message) => { console.log(message); } export default logger;
//Dummy2.js import {add, subtract} from './math.js'; console.log(add(2,3)); //5 console.log(subtract(5,3)); //2
//app.js import logMessage from './logger.js'; logMessage('This is a log message!');
button.addEventListener('click', () => { import('./notThatSmallModule.js').then(module => { module.testButton(); }); });
您有什么意见或建议,欢迎给我们留言。
分享好文,绿手指(GFinger)养花助手见证你的成长。
请前往电脑端操作