Forwarded from coding with ☕️
objectName.propertyName
objectName["propertyName"]
Forwarded from coding with ☕️
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
delete person.age;
console.log(person);Forwarded from coding with ☕️
const person = {
firstName: "John",
lastName: "Doe",
id: 5566,
fullName: function() {
return this.firstName + " " + this.lastName;
}
};
// `fullName` metodini chaqirish va uning natijasini konsolga chiqarish
console.log(person.fullName());Forwarded from coding with ☕️
coding with ☕️
const person = { firstName: "John", lastName: "Doe", id: 5566, fullName: function() { return this.firstName + " " + this.lastName; } }; // `fullName` metodini chaqirish va uning natijasini konsolga chiqarish console.log(person.fullName());
Objekt qiymatini funksiya bn chaqirish
Forwarded from coding with ☕️
person.name = function () {
return this.firstName + " " + this.lastName;
};Forwarded from coding with ☕️
const person = {
firstName: "John",
lastName: "Doe",
id: 5566,
name: function () {
return this.firstName + " " + this.lastName;
}
};
// `name` metodini chaqirish va natijasini konsolga chiqarish
console.log(person.name());Forwarded from coding with ☕️
coding with ☕️
const person = { firstName: "John", lastName: "Doe", id: 5566, name: function () { return this.firstName + " " + this.lastName; } }; // `name` metodini chaqirish va natijasini konsolga chiqarish console.log(person.name());
obyektda funksiya orqali qiymatni chaqirish
Forwarded from coding with ☕️
```
//ORIENTED OPERATING PROGRAMMING
class Typing {
constructor({el, interval, delay}){
this.el = document.querySelector(el);
this.interval = interval || 500
this.delay = delay == undefined ? 1000 : delay
this.text = this.el.innerHTML.trim()
this.el.innerHTML = ""
setTimeout(() => this.write(i), this.delay);
}
write(i = 0){
this.el.innerHTML += this.text[i]
i++;
if (i < this.text.length) {
setTimeout(() => this.write(i), this.interval);
}
}
}
new Typing({
el: ".header__content h1" ,
interval: 300,
delay:1000
});
Forwarded from coding with ☕️
class WindowSize {
constructor() {
this.width = document.documentElement.clientWidth;
this.height = document.documentElement.clientHeight;
}
updateSize() {
this.width = document.documentElement.clientWidth;
this.height = document.documentElement.clientHeight;
console.log(`Yangi o'lchamlar: ${this.width}x${this.height}`);
}
}
// Foydalanish
const windowSize = new WindowSize();
console.log(windowSize.width, windowSize.height);
// Oynani o'lchami o'zgarganda yangilash
window.addEventListener('resize', () => windowSize.updateSize());Forwarded from coding with ☕️
class WindowDimensions {
static getFullSize() {
return {
width: window.innerWidth,
height: window.innerHeight
};
}
static getViewportSize() {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight
};
}
static getScreenSize() {
return {
width: screen.width,
height: screen.height
};
}
}
// Foydalanish
console.log(WindowDimensions.getFullSize());
console.log(WindowDimensions.getViewportSize());
console.log(WindowDimensions.getScreenSize());Forwarded from coding with ☕️
class MouseTracker {
constructor(element) {
this.element = element || document;
this.x = 0;
this.y = 0;
this.initEvents();
}
initEvents() {
this.element.addEventListener('mousemove', (e) => this.handleMove(e));
this.element.addEventListener('mouseover', (e) => this.handleOver(e));
this.element.addEventListener('mouseout', (e) => this.handleOut(e));
}
handleMove(e) {
this.x = e.clientX;
this.y = e.clientY;
console.log(`Mouse harakat: X=${this.x}, Y=${this.y}`);
}
handleOver(e) {
console.log(`Mouse element ustida`, e.target);
}
handleOut(e) {
console.log(`Mouse elementdan chiqdi`, e.target);
}
}
// Foydalanish
const tracker = new MouseTracker();
// Maxsus element uchun
const myElement = document.getElementById('myElement');
const elementTracker = new MouseTracker(myElement);Forwarded from coding with ☕️
class InteractiveWindow {
constructor() {
this.size = {
width: 0,
height: 0
};
this.mouse = {
x: 0,
y: 0,
isOver: false
};
this.init();
}
init() {
this.updateSize();
window.addEventListener('resize', () => this.updateSize());
document.addEventListener('mousemove', (e) => this.trackMouse(e));
document.addEventListener('mouseover', () => this.mouse.isOver = true);
document.addEventListener('mouseout', () => this.mouse.isOver = false);
}
updateSize() {
this.size.width = window.innerWidth;
this.size.height = window.innerHeight;
console.log('Window size updated:', this.size);
}
trackMouse(e) {
this.mouse.x = e.clientX;
this.mouse.y = e.clientY;
console.log('Mouse position:', this.mouse);
}
getRelativeMousePosition() {
return {
x: this.mouse.x / this.size.width,
y: this.mouse.y / this.size.height
};
}
}
// Foydalanish
const interactiveWindow = new InteractiveWindow();
// Har 1 sekundda nisbiy pozitsiyani ko'rsatish
setInterval(() => {
const relPos = interactiveWindow.getRelativeMousePosition();
console.log('Nisbiy pozitsiya:', relPos);
}, 1000);Forwarded from coding with ☕️
Page (Sahifa) o'lchamlari - Butun HTML dokumentining o'lchami (scroll qilinadigan qismi bilan)
Forwarded from coding with ☕️
Window (Oyna) o'lchamlari - Foydalanuvchi ko'radigan brauzer oynasining hozirgi o'lchami
Forwarded from coding with ☕️
// 1. window.innerWidth / window.innerHeight
// Brauzer oynasining ichki o'lchami (scroll barlarini hisobga olmaydi)
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;
// 2. document.documentElement.clientWidth / clientHeight
// Viewport o'lchami (scroll barlarini hisobga oladi)
const viewportWidth = document.documentElement.clientWidth;
const viewportHeight = document.documentElement.clientHeight;
Forwarded from coding with ☕️
coding with ☕️
// 1. window.innerWidth / window.innerHeight // Brauzer oynasining ichki o'lchami (scroll barlarini hisobga olmaydi) const windowWidth = window.innerWidth; const windowHeight = window.innerHeight; // 2. document.documentElement.clientWidth / clientHeight…
Window height/width
Forwarded from coding with ☕️
// Butun sahifaning o'lchami (scroll qilinadigan qismi bilan)
const pageWidth = document.documentElement.scrollWidth;
const pageHeight = document.documentElement.scrollHeight;