A Javascript class library used to sort table content. It is easy to use and does not need to call the database every time.It is particularly suitable for sorting multi-table queries. With the style. display switch of Effect demonstrationUsage:1. Add JS2. Add a TABLE. Note that the TABLE must have an ID and the class is "sortable"OK, you can. It's simple.If you t
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
InJavascript object-oriented :(1) Class
We understand that the concept of classes is represented by function,So under what circumstances is the class and under what circumstances is the function? Next we will conduct a more in-depth study: Use examples to prove the truth: Example 1: Function Student (){
Currently, the implementation of JavaScript is not implemented through the "extend" keyword, but through the constructor function and prototype property to implement inheritance. First we create a animal class
JS Code
Copy Code code as follows:
var animal = function () {//This is constructor function.
this. Name = ' Pipi ';
this. Age = 10
The previous article has written a tool function $class, this article consummates below. Implement the following features
1, inheriting
2, the private property of the parent class is not inherited when the subclass inherits the parent class
Copy Code code as follows:
/**
* @param {String} className
* @param {string/function} supercls
* @par
type.For example: Var strinput=prompt ("Please enter a number:", 0);while (!strinput.match (/\d+/)) {strinput=prompt ("Please enter a number:", 0);}(3) Search (REGEXP) methodSearches for the first substring of a matching regexp regular expression from a string, returning its index position. For example: Var str= "AABCABCABC";Alert (Str.search (/abc/g));//display "1"(4) Case conversion of a String objectvar str= "abc";Str.tolowercase ()//Convert lowercaseStr.touppercase ()//convert capitalizatio
, Meow ~"}varAAA =NewAnimal ("Amphibian")varBBB =NewAnimal ("Bird Class")) Console.log (Aaa.getkind ())//Amphibian TypeConsole.log (Bbb.getkind ())//Bird ClassvarCAT_AAA =NewCat () Console.log (Cat_aaa.getkind ())//Mammal TypeConsole.log (Cat.prototype.constructor)//point to Cat, and if you don't change it back, it will be animal .//Console.log (Aaa.miao ())//undefined is not a function parent class is no u
We have used prototype property simulation class and inheritance implementation in Chapter 1. The prototype attribute is essentially a JavaScript Object. Each function has a default prototype attribute.
If this function is used to create a custom object, we call it a constructor. For example, the following simple scenario:
// Constructor
Function Person (name
(Searchvalue,replacevalue) methodThe method replaces the first occurrence of the Searchvalue substring in a string with Replacevalue and returns a new string. The original string is not affected.For example: Var str1= "AAAA";var str2=str1.replace ("A", "B");alert (str2);//Output "BAAA"alert (str1);//Output "AAAA"As you can see in the code above, you can only replace one instance with the Replace function. If you are replacing multiple instances, you need to use regular expressions, such as str.
In object-oriented programming, classes (Class) are templates of objects (object) that define properties and methods that are common to the same set of objects (also known as "instances").
The JavaScript language does not support "classes," but you can simulate "classes" in some alternative way.
First, the structural function method
This is the classical method, is also the textbook must teach the method
3 ways to define a JavaScript classseptember 29th, 2006. Tagged:javascriptintroductionJavaScript is a very flexible object-oriented language if it comes to syntax. In this article you can find three ways of defining and instantiating an Object. Even if you have already picked your favorite the doing it, it helps to know some alternatives on order to read other P Eople ' s Code.It's important to note that there is no classes in
implementation mechanism is not the same. Here's new creates an object, which points to this new object object when the subsequent point () function executes. The this.x and This.y in point are two public members of the point class, so objects of point can be accessed directly from them.
When it comes to members of class members or objects, it is unavoidable to mention accessibility issues. In
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 expre
The object class in ECMAScript is similar to the object class in Java, and all classes in the ECMAScript are inherited by this class, andall properties and methods in the object class appear in other classes . So understanding the object class makes it easier to understand o
Reference: https://www.imooc.com/article/17389Https://www.cnblogs.com/chenyangsuaige/p/6130737.htmlInheritance can be well encapsulated, subclasses can reuse the methods of the parent class directly, and add their own properties and methods.The prototype object prototype is a unique identifier for the class, and the inheritance of the class is based on prototype.
Among the several javascript class definition methods, the most common method is the combination of prototypeconstructor and dynamic prototype. There are several methods to build a class in Javascript:
1. Factory method
The Code is as follows:
Function createCar (){Var car = new Object ();Car. color = "B ";Car. leng
inheritance on the prototype, so the combination isfunction fn (name) { this.score = [90,98,99] this.name = name}fn.prototype.sayName = function() { console.log(this.name) }function a () { fn.call(this,‘kangkang‘) this.age = 3}a.prototype = new fn()a.prototype.constructor = avar c = new a()var d = new a()c.score[0] = 100console.log(c.score) //[100, 98, 99]console.log(d.score) //[90, 98, 99]console.
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.