iife (immediately invoked function expression)

PPTX 9 стр. 231,1 КБ Бесплатная загрузка

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

Прокрутите вниз 👇
1 / 9
tutorial 3: iife, context, new 3.1 iife (immediately invoked function expression) an iife is a function that runs as soon as it is defined. it helps avoid polluting the global scope by encapsulating code. (function () { let secret = "this is hidden"; console.log(secret); // output: this is hidden })(); // console.log(secret); // error: secret is not defined real-world example : initializing a library or module without exposing internal variables. (function () { let apikey = "12345"; function getapikey() { return apikey; } console.log(getapikey()); // output: 12345 })(); 3.2 context (this) the this keyword refers to the context in which a function is called. its value depends on how the function is invoked. 3.2.1 implicit binding when a function is called as a method of an object, this refers to the object. const person = { name: "alice", greet: function () { console.log(`hello, my name is ${this.name}`); }, }; person.greet(); …
2 / 9
gdetails.call(user); // output: user: user, role: regular user 3.3 new keyword the new keyword creates an instance of an object from a constructor function. it sets up the prototype chain and initializes the object. function car(make, model) { this.make = make; this.model = model; } const mycar = new car("toyota", "corolla"); console.log(mycar.make); // output: toyota real-world example : creating multiple instances of a product in an e-commerce system. function product(name, price) { this.name = name; this.price = price; } const laptop = new product("laptop", 1000); const phone = new product("phone", 500); console.log(laptop.name); // output: laptop console.log(phone.price); // output: 500
3 / 9
iife (immediately invoked function expression) - Page 3
4 / 9
iife (immediately invoked function expression) - Page 4
5 / 9
iife (immediately invoked function expression) - Page 5

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

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

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

О "iife (immediately invoked function expression)"

tutorial 3: iife, context, new 3.1 iife (immediately invoked function expression) an iife is a function that runs as soon as it is defined. it helps avoid polluting the global scope by encapsulating code. (function () { let secret = "this is hidden"; console.log(secret); // output: this is hidden })(); // console.log(secret); // error: secret is not defined real-world example : initializing a library or module without exposing internal variables. (function () { let apikey = "12345"; function getapikey() { return apikey; } console.log(getapikey()); // output: 12345 })(); 3.2 context (this) the this keyword refers to the context in which a function is called. its value depends on how the function is invoked. 3.2.1 implicit binding when a function is …

Этот файл содержит 9 стр. в формате PPTX (231,1 КБ). Чтобы скачать "iife (immediately invoked function expression)", нажмите кнопку Telegram слева.

Теги: iife (immediately invoked funct… PPTX 9 стр. Бесплатная загрузка Telegram