Front end darsliklari moduli html, css, javascript


Download 105.45 Kb.
bet10/12
Sana15.02.2023
Hajmi105.45 Kb.
#1200512
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
FRONT END full notes (7) (2022 05 08 17 42 47 UTC)

this in Event Handlers


In HTML event handlers, this refers to the HTML element that received the event:

Click to Remove Me!


Call()
const person1 = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person2 = {
firstName:"John",
lastName: "Doe",
}
person1.fullName.call(person2); // Will return "John Doe"

const module = {
x: 42,
getX: function() {
return this.x;
}
};
//when we are assigning a new var to the function’s method
const unboundGetX = module.getX;
console.log(unboundGetX()); // The function gets invoked at the global scope
// expected output: undefined

const boundGetX = unboundGetX.bind(module);
console.log(boundGetX());
// expected output: 42

10. JAVASCRIPT – Mantiqiy masalalar yechish —> (obj, array, function)
• for() with array and obj in ES6
1.

Write a function that converts an object into an array, where each element represents a key-value pair in the form of an array.

Examples


toArray({ a: 1, b: 2 }) ➞ [["a", 1], ["b", 2]]


toArray({ shrimp: 15, tots: 12 }) ➞ [["shrimp", 15], ["tots", 12]]


toArray({}) ➞ []

2.

Create a function that checks to see if two object arguments are equal to one another. Return true if the objects are equal, otherwise, return false.

Example #1


// The first object parameter.


{
name: "Benny",
phone: "3325558745",
email: "benny@edabit.com"
}


// The second object parameter.


{
name: "Jason",
phone: "9853759720",
email: "jason@edabit.com"
}
➞ false


3.
Funksiya yarating
Funksiya obyektlarni arrayda qabul qilsin. Va ikkinchi parameter uchun son qabul qiladi.
Obyekt ichidagi inson yoshlarini parameterga berganimizda ushanchaga qushib quysin.
agePerson([ {bill:24}, {Mr:25}], 3) // [ {bill:27}, {Mr:28}]


Download 105.45 Kb.

Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   12




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling