Si vous avez souvent regarder les films de HBO , puis le titre de ce post JavaScript vous ?tre familier : Oui , c'est vrai , je veux emprunter ce slogan de HBO pour d?crire le contenu de ce post : il vous fournira les concepts de base JavaScript , et vous serez en mesure d' acc?der , de comprendre la programmation web langage JavaScript facilement et rapidement
Exemple, les codes JavaScript pour essayer ? l'heure actuelle , cet article JavaScript tutorial nous 5 pi?ces et je mettrai ? jour s'il ya nouveau chapitre , en attendant , vous pouvez passer par :
? D?clarations de fonctions JavaScript et des expressions de fonction JavaScript - Concepts de base
? JavaScript Prototype : Quelques concepts de base
? 5 Chef Concepts H?ritage JavaScript
? Concepts simples sur les types et les objets en JavaScript POO
? Top 10 Meilleurs livres JavaScript que les d?butants devraient apprendre
- Demo
- Agrandir
- Recharger
- New window
Gratuit iPage hébergement Web pour la première année MOMENT
Si vous êtes toujours à la recherche d'un fournisseur d'hébergement Web fiable avec des tarifs abordables, pourquoi vous ne prenez pas un peu de temps pour essayer iPage, seulement avec $1.89/month, inclus $500+ Crédits supplémentaires gratuites pour le paiement de 24 mois ($45)?
Plus de 1.000.000 de clients + existisng peuvent pas avoir tort, vraiment vous n'êtes pas aussi! Plus important encore, lorsque vous enregistrez l'hébergement web à iPage grâce à notre lien, nous allons être heureux de renvoyer un plein remboursement. C'est génial! Vous devriez essayer iPage hébergement web GRATUITEMENT maintenant! Et contactez-nous pour tout ce que vous devez savoir sur iPage.
While the Javascript language offers many of the constructs required for object-oriented programming, they remain largely unused. Today we’ll take a look at how to start with object-oriented programing in Javascript. by defining a class in Javascript. We’ll use the simple HTML file to call our script file,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Hello Javascript!</title> <script type="text/javascript" src="MyScript.js"></script> </head> <body> Hello Javascript! </body> </html>
Now let’s create a class definition (in MyScript.js). Note that there is no ‘class’ keyword in Javascript, the class definition is just a function definition,
function MyClass() { // Public field this.aPublicField = "This is a public field of the type MyClass"; // Private field var aPrivateField = "This is a private field of the type MyClass"; // Public method this.aPublicMethod = function() { // Use the private method if (aPrivateMethod()) { return this.aPublicField; } else { return aPrivateField; } } // Private method function aPrivateMethod() { return true; } // Oops! We can expose the private field this.exposePrivateField = aPrivateField; // and the private method this.exposePrivateMethod = aPrivateMethod; } // Create an instance of MyClass using the ‘new’ keyword var myclass = new MyClass(); // Get the public field alert(myclass.aPublicField); // Call the public method alert(myclass.aPublicMethod()); // Call the private field – can’t get to them directly alert(myclass.exposePrivateField); alert(myclass.exposePrivateMethod());
So it’s pretty simple to create a class in Javascript. We can also create a runtime field for the class,
// Create an instance of MyClass var myclass = new MyClass(); // Create a field at runtime myclass.aRuntimeField = "This is a runtime field of the type MyClass"; // View the field value alert(myclass.aRuntimeField);
Part 2: Javascript Inheritance
Now that we created a base Javascript class in the first post, let’s inherit from it to get a derived class.
// Define the derived function (remember there is no 'class' keyword in Javascript) function MyDerivedClass() { } // Derive from MyClass, equivalent to –> public class MyDerivedClass : MyClass MyDerivedClass.prototype = new MyClass(); // Create an instance of the derived class var myderivedClass = new MyDerivedClass(); // Get the public field alert(myderivedClass.aPublicField); // Call the public method alert(myderivedClass.aPublicMethod());
Woah! That was simple! Notice that MyClass’s private methods and the runtime field (aRuntimeField) we gave to MyClass in the last post is not available to MyDerivedClass.
Let’s override the base classe’s public fields and methods and see what happens,
// Define the derived function (remember there is no 'class' keyword in Javascript function MyDerivedClass() { // Override the base's public field this.aPublicField = "This is a public field of the type MyDerivedClass"; // Override the base's public method this.aPublicMethod = function() { return this.aPublicField; } } // Derive from MyClass, equivalent to –> public class MyDerivedClass : MyClass MyDerivedClass.prototype = new MyClass(); // Create an instance of the derived class var myderivedClass = new MyDerivedClass(); // Get the public field alert(myderivedClass.aPublicField); // Call the public method alert(myderivedClass.aPublicMethod());
You’ll see that the base classes public fields and methods have been overridden in the derived class.
We can obviously derive again,
// Derive from MyDerivedClass function MyDerivedDerivedClass() { // Override the base's public field this.aPublicField = "This is a public field of the type MyDerivedDerivedClass"; // Override the base's public method this.aPublicMethod = function() { return this.aPublicField; } } // Derive from MyDerivedClass, equivalent to –> public class MyDerivedDerivedClass : MyDerivedClass MyDerivedDerivedClass.prototype = new MyDerivedClass(); // Create an instance of the derived class var myderivedderivedClass = new MyDerivedDerivedClass(); // Call the public method alert(myderivedderivedClass.aPublicField);
- Sent (0)
- Nouveau
Save up to 630$ when buy new iPhone 15
GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project
https://tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools
chatGPTaz.com, chatGPT4.win, chatGPT2.fun, re-chatGPT.com
Talk to ChatGPT by your mother language
Dall-E-OpenAI.com
Generate creative images automatically with AI
AIVideo-App.com
Render creative video automatically with AI
Javascript is ... Réponse
Réponse
Jquery instead of javascript ... @ Cao Phong Réponse
For example : Javascript:
document.style.color = "red"; --> so complicated to remember
Jquery:
$(div).css ("color","red"); ->is that okey for coding ????