Javascript Programming Tutorials, Guides & Best Practices
Explore 93+ expertly crafted javascript tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.
Adblocker Detected
It looks like you're using an adblocker. Our website relies on ads to keep running. Please consider disabling your adblocker to support us and access the content.
Tutorial
javascript
البرمجة الكائنية (OOP) في JavaScript: المفاهيم الأساسية والتطبيقات
class BankAccount {
constructor(owner, balance) {
this.owner = owner;
this._balance = balance; // خاص
}
deposit(amount) {
if (amount > 0) {
this._balance += amount;
console.log(`تم إضافة ${amount} إلى الحساب.`);
}
}
getBalance() {
return this._balance;
}
}
const account = new BankAccount("علي", 1000);
account.deposit(500);
console.log(account.getBalance()); // 1500في هذا المثال، خاصية _balance مخفية ولا يمكن الوصول إليها مباشرة من خارج الفئة.
Sep 26, 2024
Read More