ObjectECMAScript is a highly abstract object-oriented language that handles objects. There are also basic types, but they can also be transformed into objects if they are needed.Definition: An object is a series of properties and a unique prototype object. The prototype
JavaScript, of course, is no exception, but about the object of reference issues, you have considered it? The common practice is to have a series of methods for sharing classes, rather than duplicating a function for each object. Here's a look at copying a function for each object.
Copy Code code as follows:
The extended implementation code of some Array and String prototype objects collected. For details about js learning, refer. It can also customize the expansion of string and array data. From the worry-free script collection, some are indeed good, more practical, it is worth collecting.
How to extend the prototype object of Array
The Code is as follows:
// Del
1, because the process of looking up values in a prototype is a search, any modifications we make to the prototype object can be immediately reflected from the instance---even if the instance was first created and the prototype is modified. The code is as follows:function Person () {} var friend=New person (); Person.p
In JavaScript, Object. prototype. toString is used to determine whether it is an array.
Why Object. prototype. toString instead of Function. prototype. toString or others? This is related to their toString interpretation method. T
The examples in this article describe the way JavaScript uses prototype to implement object-oriented methods. Share to everyone for your reference. The specific analysis is as follows:
Prototype is a property of a Function object that points to another
JS does not provide the so-called class inheritance, it is said that in 2.0 to join this way of inheritance, but to all browsers to achieve 2.0 of the characteristics that must be more than n years. Yesterday saw a video of Crockford, which explained the way JS inheritance, according to the PPT said, a total of three categories: Prototypal,pseudoclassical,parasitic inheritance.
The following is a brief introduction to prototype inheritance: When a fu
Object-oriented javascript: using the 'prototype' Property
Since JavaScript 1.1, it has a built-in object called prototype. It can be used to expand JavaScript and write custom attribu
Basic knowledge1. Strictly speaking, in JS, only objects without class2. Objects can have unique attributes and methods. That is, the attributes and methods of an object are supersets of classes.3. ecmascript can recognize two types of objects.A type of object called Native object belongs to the linguistic category;A host obj
To demonstrate that JavaScript is a thorough object-oriented language, it is necessary to start with the object-oriented concept and discuss several concepts of object-oriented: 1. everything is an object. objects are encapsulated and inherited. message Communication is used
Javascript's new is just a simulation of the class. This is why JavaScript classes are not classes in the industry-because they are simulated.
In fact, the New Keyword of JavaScript only does five things.
1. Create an object2. Search for all the methods and attributes on the prototype of the class and copy them to the created
) this.width=650; "title=" Untitled. jpg "src=" http://s3.51cto.com/wyfs02/M00/6D/28/ Wkiom1vdefzzyfeeaafdskcrbam427.jpg "alt=" Wkiom1vdefzzyfeeaafdskcrbam427.jpg "/>In this case, the expert's advice is "the safest way is not to make any assumptions". As a result, we can extract the hasOwnProperty method in any secure location ahead of time, and take advantage of the lexical scope features of an immediately executed anonymous function to achieve the following solution:(function Testownproperty
Let's look at two phenomena first:1. Component Form declaration prototype (partial override), the prototype constructor is a host function instead of an object, just like adding properties directly to the host constructorfunction Dog () {this.tail = true;} New two dogs, note that at this time there is no definition prototypevar benji = new Dog (), var rusty = new
"; BASECLASS.PROTOTYPE.PUBLICMETHOD2=function() {alert ("PublicMethod2");} Baseclass.staticname= "Static"; Baseclass.staticmethod=function() {alert ("Staticmethod");} MyClass=function(){ varme =NewBaseClass (); Me.getname=function() { //cannot access the private properties and methods of the base classalert (privatename); Privatemethod (); } //define a public method for a subclassMe.othermethod =function() {alert ("Othermethod"); } returnme;}//Through
To demonstrate that JavaScript is a thorough object-oriented language, it is necessary to start with the object-oriented concept and discuss several concepts of object-oriented: 1. everything is an object. objects are encapsulated and inherited. message communication is used
, the constructor creates the object's method on the stage, using the method of the constructor, that is to solve the problem of repeated instantiation, and solve the problem of object recognition. The code is as follows.var box= new box (' Belle ', +); Alert (box instanceof box); Returns true, clearly recognizing that box is subordinate to boxThe constructor method is compared with the Factory mode method, the constructor method does not display the
prototype--prototypes for dynamically adding properties and behaviors to objectsFirst define a constructor functionSmall accessory function Gadget (name, color) {this.name = Name;this.color = Color;this.whatareyou = function () {return ' I am ' + this.co Lor + ' + this.name;} This.get = function (what) {return this[what];//object is similar to array, JS [] can be subscript or object's property}}Adding prope
Adding a new method to the built-in object using the prototype attribute in Javascript
This example describes how to add a new method to a built-in object using the prototype attribute in Javascript. Share it with you for your ref
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.