ArticleDirectory
The simplest function (method ):
Form Verification Function
Methods (functions) in the object)
Sub-methods in the Method
Method Return Value
Methods can be passed as parameters (delegate in JS, callback function)
Back to directory
The previous article mainly talked about classes in JS. Many of my friends have replied to my article. I am very grateful to you for your reply to some of your questions, "class
= house;}PeopleHope. prototype. hope = function () {document. write ("I want to own money, house") ;}; // This is the prototype, and will be initialized by the constructor to the attributes of the object.For (var p in PeopleHope. prototype){Document. write ("the prototype has come out! \ T "+ p +" }2. SimulationIn fact, the "class" in Javascript is just a function. Go directly to the code!Function PeopleHo
A very good javascript class. A very good javascript class.
The Code is as follows:
/** Author: aoao* Homepage: http://www.loaoao.com* Email: loaoao@gmail.com/QQ: 2222342* Copyright (c) 2006 aoao* Licensed under a Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5)*/Var jscc = new Ob
Online blog Forum appeared a lot of JavaScript class inheritance methods, browse some, not without comments, is not running effect, so I wrote a simple and understandable version, with the test code at the bottom.The article has just been accidentally deleted, so it is re-made, and the example is strengthened.(function () {Function.prototype.extend = function (BaseClass) {This is a function object.var oldpr
The JavaScript class is the default prototype object inheritance:var person = function () { this.name = "people"; This.hello = function () { console.log ("Hello User:" + this.name);} } var user = function () { this.name = "user"; This.hello = function () { User.prototype.hello.call (this, arguments); Console.log ("Hello User:" + this.name);} } User.prototype = new Person ();
comparable to desktop programs.
Okay, no more nonsense, now start with a JavaScript development framework prototype_1.3.1 (hereinafter referred to as prototype). I originally wanted to introduce the advanced application of JavaScript, but afraid of the level is not enough, said the lack of organized, so on the combination of prototype, the way will mention the use of JS Grammar.
Here is the first two para
());//Factory (Factory mode)ConstProto= { Drive(){ Console.Log(' vroom! '); }};function Factorycar(){ return Object.Create(Proto);}ConstCar3= Factorycar();Console.Log(Car3. Drive());These methods store the method in a shared prototype and then selectively support private data through the closure of the constructor. In other words, they almost have the same characteristics, so they can often be used interchangeably.> in JavaScript, any function
This article describes how to solve the problem of no-parameter and parameter-class inheritance in Javascript. This article explains the problem of non-parameter class inheritance and the problem of parameter-class inheritance, and provides a solution, for more information about Ja
This article mainly introduces the class Array objects in JavaScript. an object is not created by the Array constructor and still presents the behavior of an Array. in this case, these objects are called "class array objects". For more information, see JavaScript. an array is a special object whose property
');
}
return " -0-";
});
The Inherits method is similar to the Java extends. The Uber method is similar to the Java super. It makes a method call the method of the parent class (changing the name to avoid conflicts with reserved words).
We can write this.
Copy Code code as follows:
Myzparenizor = new Zparenizor (0);
myString = Myzparenizor.tostring ();
This time, mys
defined while defining "class" in JavaScript.
Using constructors
JavaScript uses classes in the same way as C #, and the new keyword follows the constructor.
var p = new person ();
Defining Properties and methods
Now that we have defined the person class, you can add some properties and methods to th
process, we have a wonderful name: Class instantiation. The newly created object will have all the attributes and methods defined by the class. In the traditional class-based language, we can do this:
public class Shape {private int height;private int width;public Shape(int
immediately delete the original value's object form.For example:var num = 123; NUM.ABC = "a"; Num.abc = undefined and a chestnut to digest and digest.var str = "abc"; str + = 1; var test = typeof (str); if (test.length = = 6) {test.sign = "typeof return result may be string";} Doucment.write (test.sign); See what the final output is? A rough look at Test is a string, just good length is 6, print "
I have been unemployed at school for one and a half months. I haven't found an internship yet. It's a tragedy and it hurts. cookie. js has changed to the pure javascript version. For future projects, I only need to add a function to get all the cookie key values on the page.
The function is assembled by analyzing the document. cookie string.
Review the operations on cookies in javascript:
You can use docume
The function is assembled by analyzing the document. cookie string.Review the operations on cookies in javascript: You can use document. cookie = "userId = 111"; to add a cookie.The full version can be used:Document. cookie = "userId = 111; domain = .google.com; path = \; secure = secure; expire =" + date. toGMTString ();You can set the cookie expiration time, domain name, and path.You only need to delete i
Copy Code code as follows:
function class name (parameter table) {
this. property;
......
this. function;
}
In this way, functions and data members are all using the "this." To achieve.
We define a simple class student and then construct it and implement an output function.
Copy Code code as follows:
(Hey, it's to
is defined in JavaScript.Using constructorsJavaScript uses classes in the same way as C #, followed by the constructor for the new keyword.var p = new person ();Defining Properties and methodsNow that we have defined the person class, you can add properties and methods to the person class.Defining propertiesWhen we talk about JavaScript objects, we talk about the object's property settings and access.This
Some time ago, after learning "ajax self-taught manual", I realized that javascript can still be written like this.
I have learned the concepts of classes in Java, C #, and VB, and classes have functions such as inheritance, encapsulation, and polymorphism. Javascript is not an object-oriented language, but an explanatory language.
But we can also use JavaScript
Because most of the project JAVASCRIPT,CSS client work is another colleague in charge, the colleague and special busy can not be reconstructed, the boss also just make suggestions did not immediately implement refactoring. But I've also changed a little bit of client bugs in the last few days, it is true that the code is a little foggy, I do not know which mountain, easy to move code, so I started to tinker with the love and hate of
Copy codeThe Code is as follows:Function class name (parameter table ){This. Attribute;......This. function;} In this way, both functions and data members are implemented using "this.Let's define a simple class student, and then construct it and implement an output function.Copy codeThe Code is as follows: (It's too easy, too)Well .. In short, it's better to unde
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.