javascript prototype tutorial

PPTX 10 стр. 1,5 МБ Бесплатная загрузка

Предварительный просмотр (5 стр.)

Прокрутите вниз 👇
1 / 10
tutorial 4: prototype, __proto__, async, event loop 4.1 prototype every javascript object has a prototype, which allows inheritance of properties and methods. prototypes enable objects to share functionality without duplicating code. function animal(name) { this.name = name; } animal.prototype.speak = function () { console.log(`${this.name} makes a sound`); }; const dog = new animal("dog"); dog.speak(); // output: dog makes a sound real-world example : extending a base class to create specialized objects. function vehicle(type) { this.type = type; } vehicle.prototype.start = function () { console.log(`${this.type} is starting...`); }; function car(make, model) { vehicle.call(this, "car"); this.make = make; this.model = model; } car.prototype = object.create(vehicle.prototype); const mycar = new car("toyota", "corolla"); mycar.start(); // output: car is starting... 4.2 __proto__ the __proto__ property points to the prototype of an object. it allows you to access inherited properties and methods. const obj = {}; console.log(obj.__proto__ === object.prototype); // output: true real-world example : accessing …
2 / 10
completion (or failure) of an asynchronous operation. function fetchdata() { return new promise((resolve, reject) => { settimeout(() => resolve("data fetched"), 1000); }); } fetchdata().then((data) => console.log(data)); // output: data fetched real-world example : fetching data from an api. function fetchuserdata(userid) { return new promise((resolve, reject) => { settimeout(() => { const users = { 1: "alice", 2: "bob" }; resolve(users[userid]); }, 1000); }); } fetchuserdata(1).then((user) => console.log(user)); // output: alice 4.3.2 async/await async/await provides a cleaner syntax for working with promises. async function getdata() { const data = await fetchdata(); console.log(data); // output: data fetched } getdata(); real-world example : chaining multiple asynchronous operations. async function getuserandposts(userid) { const user = await fetchuserdata(userid); const posts = await fetchposts(user); console.log(`${user}'s posts:`, posts); } getuserandposts(1); 1. event loop and asynchronous javascript understanding how javascript handles asynchronous operations is crucial. the event loop is the mechanism that allows javascript to perform non-blocking operations …
3 / 10
// loading data... // waiting for data... // data loaded image1.gif
4 / 10
javascript prototype tutorial - Page 4
5 / 10
javascript prototype tutorial - Page 5

Хотите читать дальше?

Скачайте все 10 страниц бесплатно через Telegram.

Скачать полный файл

О "javascript prototype tutorial"

tutorial 4: prototype, __proto__, async, event loop 4.1 prototype every javascript object has a prototype, which allows inheritance of properties and methods. prototypes enable objects to share functionality without duplicating code. function animal(name) { this.name = name; } animal.prototype.speak = function () { console.log(`${this.name} makes a sound`); }; const dog = new animal("dog"); dog.speak(); // output: dog makes a sound real-world example : extending a base class to create specialized objects. function vehicle(type) { this.type = type; } vehicle.prototype.start = function () { console.log(`${this.type} is starting...`); }; function car(make, model) { vehicle.call(this, "car"); this.make = make; this.model = model; } car.prototype = object.create(vehicle.prototype); const mycar ...

Этот файл содержит 10 стр. в формате PPTX (1,5 МБ). Чтобы скачать "javascript prototype tutorial", нажмите кнопку Telegram слева.

Теги: javascript prototype tutorial PPTX 10 стр. Бесплатная загрузка Telegram