JavaScript itself does not support object-oriented, it does not have an access control character, it does not define the class's keyword class, it does not support inherited extend or colons, nor does it support virtual functions, but JavaScript is a flexible language, Let's take a look at how JavaScript, without the k
Objective
For JavaScript, classes are optional (not necessarily) design patterns, and implementing classes in [[Prototype]] languages like JavaScript is lame.
This kind of lame feeling is not just from grammar, although grammar is a very important reason. JS has a lot of grammatical shortcomings: cumbersome and messy. Prototype refers to explicit pseudo polymorphism when attempting to invoke a function of
see through Firebug that Requirejs will insert a.js and b.js on the current page and declare a
Case three: Requirejs inserted
Use Requirejs to define JavaScript modules
The JavaScript module here is different from the traditional JavaScript code in that it does not need to access global variables. The modular design allows
object comes with a property that is constructor. It refers back to the constructor associated with the prototype.
Copy Code code as follows:
function Peoplehope (money,house)
{
This.money = money;
This.house = House;
}
PeopleHope.prototype.hope = function () {document.write ("I want to own money, house");};/ /This is the prototype, which is initialized to the property of the object by the constructor.
For (var p in Peoplehope.prototype)
{
document
ReproducedJavaScript differs from other object-oriented languages, such as C++,java or PHP. It is not a class-based language, but a prototype-based one.1. Object creationIt is very easy to create a class in javascript:var myObject = { , function() { alert (this . AVar);} }You do not have to create an object by defining a class and then instantiating the
This blog is reproduced in: http://devbean.javaeye.com/blog/406265
Class is one of the core concepts of object-oriented programming. A class represents the abstraction of a class of things with similar attributes. Starting from this article, we will officially enter the object-oriented section of JavaScript. The first
To set the style of an element by using the ClassName property:
The id= "P1" element is added to the "class name one" style by classname. When you click the "Add Style" button, the first paragraph of text adds a style.
The id= "P2" element is modified by classname to the style "class name is two". When you click the "Change Appearance" button, the second paragraph of text changes style.
I will not ' use strict ', so the article is not rigorous. Originally, the current JavaScript is what you love to see it what it is.For example, what do you think of this remark:var o = new SomeClass ();Create a pair of classes, yes. At first glance, you don't know if this is C # or JavaScript. What about the definition of this class?function SomeClass () { (fun
The prototype of the javascript class. Here I would like to put it simply: javascript itself does not have strict Inheritance like java. We say that javascript inheritance, it is also similar to the object-oriented language, so although javascript supports object-oriented pr
But there is no class concept in JavaScript, the so-called class is also simulated, through the function of the closure to simulate the class members and private members (for closures can see
crossing boundaries: Closures)。 Here we will look at the "class" in
In small projects for JavaScript use, just write a few function on the line. But in large projects, especially in the development of the pursuit of a good user experience of the site, such as SNS, will use a lot of javascrpt, sometimes JavaScript workload than C #, then write a bunch of function, it will appear very messy, disorganized, even a naming conflict, It's cumbersome to manage and maintain. In this
do is often incredible, and some functions can even be equivalent to the desktop program.
Now we can start with a javascript development framework prototype_1.3.1 (prototype. I would like to introduce the advanced javascript applications first, but I am afraid that the level is not enough and that it is not organized. Therefore, combined with prototype, I will mention js syntax usage by the way.
The follo
Array.prototypeThe standard method on an object is designed to be reused on other objects-even if it is not an object that inherits from an array. Therefore, passbook some class array object (Array-like Objects) in JavaScript. A typical example is the arguments object of the function, which is described in Item 22. The object does not inherit from Array.prototype, so we cannot directly invoke arguments.fore
First of all, we need to declare that at least no class exists in Javascript so far. The so-called "class" is actually not a real class, it is just like a class in other object-oriented languages. Its essence is Function + prototype ). Some people say that
These years have focused on project management, with fewer codes. These days more idle, want to the original experience precipitation down, one is to do a good record, later if you forget to get back as soon as possible, the second is to write a blog, is to practice writing it.In this case, the JavaScript class library was written. As we all know, Javacript is a very interesting language. Although it is the
desktop program.
Now we can start with a javascript development framework prototype_1.3.1 (prototype. I would like to introduce the advanced javascript applications first, but I am afraid that the level is not enough and that it is not organized. Therefore, combined with prototype, I will mention js syntax usage by the way.The following is the first two pieces of code in the framework:
Var Prototype = {Ver
Almost 20 years ago, when JavaScript was born, it was just a simple web scripting language. If you forget to fill in the user name, it jumps out a warning.Today, it becomes almost omnipotent, from the front-end to the back-end, with a variety of unthinkable uses. Programmers use it to accomplish larger and larger projects.The complexity of JavaScript code also rises linearly. A single page contains 10000 li
In JavaScript, a function is actually an object, each function is an instance of a function class, and since it has its own properties and methods, the function name is actually a pointer to a function object and is not bound to a function.Declaration of a functionWay one: Conventional wayfunction sum1 (num1,num2) {2 return num1+3} Mode two: function expressionvar sum2=function(num1,num2) {2 ret
JavaScript as a weak type of speech, there is no similar to the concept of "class" in java,c#, but there are many times in the actual development of such requirements, there are now know that there are two ways to simulate.1. By declaring an object, you can have the following code:var people = { age:12, name: "Jack", Sex: "Male", setage:function (value) { this.age = va
containing, and 30
Simple enough, now S is a 3-element stream:10, and 30; In a sequential order. We can use S.length () to look at the length of this stream, and use S.item (i) to retrieve an element from it by index. You can also get the first element of the stream by calling S.head (). Let's actually do the following:
Copy Code code as follows:
var s = stream.make (10, 20, 30);
Console.log (S.length ()); Outputs 3
Console.log (S.head ()); Outputs 10
Console.log (S.item (
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.