إليك بعض الأمثلة البسيطة لاستخدام JavaScript داخل صفحات HTML :
1. الطريقة البسيطة لطباعة نص على واجهة المستخدم:
JavaScript Example
JavaScript Example
2. حساب العمر باستخدام تاريخ الميلاد:
Calculate Age
Calculate Age
3. إظهار نافذة تاكيد عند النقر علي زر:
Confirmation Box
Confirmation Box
يمكنك تجربة هذه الأمثلة عبر تشغيلها في محرر HTML أو المتصفح مثل google chrome. إليك مزيدًا من الأمثلة على استخدام JavaScript :
4. إنشاء قائمة ديناميكية:
Dynamic List
Dynamic List
5. عرض الوقت الحالي في الوقت الفعلي:
Real-time Clock
Real-time Clock
6. تغيير لون الخلفية باستخدام أزرار
Change Background Color
Change Background Color
جرّب تشغيل هذه الأمثلة باستخدام visual studio code لتفهم كيف يمكن استخدام JavaScript لتحسين وظائف صفحات الويب.
ملحوظة : يمكنك تغيير العلامات double”” بالعلامات single ” في حاله اي من الامثلة لا تعمل معك
امثلة متقدمة JavaScript
Promises و Async/Await:
- تستخدام لإدارة العمليات الغير متزامنة بشكل فعّال، مما يسمح بتنظيم الشفرة وتجنب الرموز المتشعبة (Callback Hell).
function getDataWithPromise() {
return new Promise((resolve, reject) => {
fetch('https://api.example.com/data')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok.');
}
return response.json();
})
.then(data => {
resolve(data);
})
.catch(error => {
reject(error);
});
});
}
// استخدام الوعد
getDataWithPromise()
.then(data => {
console.log('البيانات:', data);
})
.catch(error => {
console.error('حدث خطأ:', error);
});
ES6 Destructuring:
- استخدام تفكيك الكائنات والمصفوفات لتعيين القيم بشكل مباشر، مما يجعل الشفرة أكثر قراءة وفعالية.
// Destructuring objects
const { firstName, lastName } = person;
// Destructuring arrays
const [first, second, , fourth] = myArray;
Higher Order Functions:
- استخدام الدوال العليا لتمريرها كمعلمة أو إرجاعها من أخرى، مما يُمكّن التعامل معها بشكل ديناميكي.
function higherOrderFunction(callback) {
// Perform some operations
callback();
}
function myCallback() {
console.log('This is a callback function');
}
higherOrderFunction(myCallback);
التعامل مع DOM بشكل ديناميكي:
- استخدام JavaScript لتحكم في العناصر والمحتوى داخل صفحة الويب بشكل ديناميكي.
const element = document.getElementById('myElement');
element.style.color = 'red';
function createNewElement() {
const newElement = document.createElement('div');
newElement.textContent = 'New content';
document.body.appendChild(newElement);
}
Generators:
- تستخدام لإنشاء دوال قابلة للإيقاف وإنتاج قيم على مراحل. مثال:
function* generator() {
yield 1;
yield 2;
yield 3;
}
const gen = generator();
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
Proxy Objects:
- تستخدام لإضافة سلوك مخصص عند الوصول إلى الخصائص أو التعامل مع الكائنات او يمكنك الرجوع الي JavaScript مثـــــــــــــال :
const handler = {
get: function(target, prop) {
return prop in target ? target[prop] : 'Property does not exist';
}
};
const proxyObj = new Proxy({ name: 'John' }, handler);
console.log(proxyObj.name); // John
console.log(proxyObj.age); // Property does not exist
Asynchronous Iteration:
- تستخدام لتمثيل العناصر بشكل متسلسل عبر الوقت. مثال:
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
const asyncIterable = {
async *[Symbol.asyncIterator]() {
for (let i = 1; i <= 5; i++) {
await delay(1000);
yield i;
}
}
};
(async () => {
for await (const num of asyncIterable) {
console.log(num);
}
})();
WebSockets:
- تستخدام لإنشاء اتصال ثنائي الاتجاه بين العميل والخادم لتبادل البيانات في الوقت الفعلي.
const socket = new WebSocket('wss://example.com');
socket.addEventListener('open', () => {
console.log('Connected to server');
});
socket.addEventListener('message', event => {
console.log('Received message:', event.data);
});
socket.send('Hello Server');
هذه أمثلة متقدمة في JavaScript تُظهر الاستخدام الفعّال والقوي لبعض الميزات المتقدمة في اللغة. تلك الأدوات والمفاهيم تساعد على كتابة شفرة أكثر تنظيمًا وفعالية وديناميكية في تطوير تطبيقات الويب.
Sharing to
Facebook
Twitter
LinkedIn
Post Views: 24
セックス ドール彼らのサービスの質の高さが、顧客からの高い満足度と信頼に繋がっています.comは、安全で便利なショッピング体験を提供することにも力を入れています.
ラブドール えろThe website is equipped with state-of-the-art security features to protect your personal and financial information,ensuring that your transactions are safe and secure.
ラブドール えろThis level of customer care is a key factor that sets com apart from other retailers and contributes to their reputation for excellence.The website employs advanced security measures to protect your personal and payment information,
Somehow none of it is weird. The best part of Hedonism isn’t the penises orえろ 人形 the all-inclusive drinks or the spying on other couples or the Caribbean breezes felt on nipples
The blog is meticulously researched,ラブドール エロwith references to academic papers and expert interviews,
adding to the doll’s natural and lifelike feel.courteous,美人 セックス
providing a nuanced view that is both fair and insightful.ラブドールYour balanced approach,
‘This person knows me intimately,オナドールhe knows my feelings,
Your article on [specific topic] offered some truly original insights that I found both refreshing and thought-provoking.ダッチワイフThe way you approached [specific subtopic] with a fresh perspective and challenged conventional wisdom was particularly impressive.
Mix a mild, antibacterial soap with warm water to create a gentle cleaning solution.えろ 人形 Avoid using harsh chemicals or abrasive cleaners as they can damage the silicone.