Scripting of JavaScript classes
Defining variables and methods internally
The this declaration is used to define common public properties and public methods
In the internal var declaration, or simply do not write Var (implicitly declared) is the dead Yo property with private method
An instance of a class can only access public properties and public methods functionPet (_name,_age,_
parameter, and a JavaScript object that contains one or more property descriptors **/Object.create () He can give an empty box what you want him to put on, it's cheap, it's small, it can go straight in the pocket, and it's very good in scalability. His function is to copy a radio-making machine at a very small cost.First of all, we create an empty box (function object), of course, you can also give the empty box you want to install things;1 var funct
, Bulfei? Is the boolean inside of the reverse operation, which is not well. You say is, then I want negative, you say greater than I say less than equal. That's the truth. Character classes also support Boolean operations, with the addition of the symbol "^" in the front of the character set in parentheses.Match any one character except the letter A,b,c
The code is as follows
Copy Code
var pattern =/[^abc]/;
JavaScript
Turn from: http://www.rainleaves.com/html/1684.html
A JavaScript static class is simply a class that does not have to be created by new, and can be used directly, like the built-in global class of JavaScript, such as math and object.
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", setag
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 (
How to solve the problem of no parameters and parameter class inheritance in Javascript
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
Before you do something, be clear about the benefits of doing it, and believe that no one is willing to do things for no reason at all. Generally speaking, when we are designing a class, in fact, you want to reduce the repetition of the code, the use of inheritance can be perfect to do this, with the inheritance mechanism, you can on the basis of existing classes again to design and make full use of the various methods they already have, and the desig
Previously discussed how to write in JavaScript. However, private implementations are not discussed. Look at this article.
We know that the implementation of JS private property is the essence of Var + closure. As follows
Copy Code code as follows:
function person (n, a) {
Public
THIS.name = n;
Private
var age = A;
This.getname = function () {
return this.name;
}
This.getage = function () {
return age;
}
}
JavaScript Data Validation Class/*JavaScript: Authentication class Author: Yang Bo date:201603231, User name authentication 2, password Authentication 3, repeat password verification 4, mailbox verification 5, mobile phone number verification 6, Verification code verificatio
Currently, javascript implementation inheritance is not implemented through the "extend" keyword, but through the constructor function and prototype attributes. First, create an animal class.Js CodeCopy codeThe Code is as follows:Var animal = function () {// This is the constructor function.This. name = 'pipi ';This. age = 10;This. height = 0;}// Create an animal instanceVar a1 = new animal (); The differen
processing and defining private variables, you can also use var to define private functions // private function Shape3 () {var draw = function () {// private function} this. draw2 = function () {// common functions that can be seen from the outside} var c = new Shape3 (); c. draw2 (); // use javascript to simulate OOP programming function Shape4 (ax, ay) {var x = 0; var y = 0; var init = function () {x = ax; y = ay;} init (); this. getX = function ()
This article describes the prototype attribute in JavaScript. This attribute is an important basis for understanding JavaScript classes and inheritance. We have used prototype property simulation class and inheritance implementation in Chapter 1. The prototype attribute is essentially a JavaScript Object. Each function
There are several ways to build a class in javascript:
1.Factory Mode
Copy Code code as follows:
function Createcar () {
var car = new Object ();
Car.color= "B";
car.length=1;
Car.run=function () {alert ("Run");}
return car;
}
Once you have defined such a function, you can use:
var car1 = Createcar ();
var car2 = Createcar ();
To create a new object, the problem is that e
.
Prototype
This method uses the prototype attribute of the object to view it as the prototype on which the object is created. Here, we use an empty constructor to set the class name, and then all the attributes and methods are directly assigned to the prototype attribute. Rewrite the previous example. The Code is as follows:
The Code is as follows:
Function Car (){}Car. prototype. color = "red ";Ca
The object in JavaScript is the base class for all objects in JS, meaning that all objects in JS are derived from object objects. Object objects are used primarily to encapsulate arbitrary data into an object form.
Introduction of Object class
The object class is the base class
The object class is the most basic class in JavaScript and is used to create generic objects that typically store data with these objects.1. Object objects1.1. Creating Object ObjectsThere are two ways of creating object objectsfirst method of creation : New Object ()var obj = new Object ();The second method of creation : {}var obj = {};var Obj2 = {"
JavaScript does not have native inheritance syntax, which is really confusing, but the wisdom of the vast majority of people is endless. Recently, is tasting a little from the source of the sweetness of learning, do not share it is difficult to calm the mood of excitement. Shortly before the video playback plugin was remodeled, Videojs was found to be an excellent open source project. After a period of time in-depth study of its source code, found tha
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.