Javascript Array object prototype attribute, arrayprototype
The prototype attribute enables you to add attributes and methods to an object.
Syntax:
Object. prototype. name = value
The main content of this article is from JavaScript advanced programming, object-oriented and prototyping chapters:
1. Factory mode
ECMAScript can create objects through Factory mode:
Factory mode
function CreateObject (name, age) {
var obj = new Object (); Create object
obj.name = name;
function inherit (p) {if (p = = null) throw TypeError (); P is an object, but cannot be nullif (object.create)//If object.create () existsReturn Object.create (P); Use it directlyvar t = typeof P; Otherwise further detectionif (t!== "Object" t!== "function") throw TypeError ();function f () {}; Define an empty constructorF.prototype = p; Set its prototype proper
From: JavaEye.com prototype provides a JavaScript object-oriented infrastructure, which can be used for object-oriented programming. The method for defining object types is as follows:
Var Person = Class. create (); Person. prototype
We had a lot of detail in front of us. In order to make everyone more clear about the use of prototype details;Now it is possible to integrate the previous knowledge and write a function for high-speed construction of the inheritance relationship based on the prototype chain:function extend (child, Parent) {var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F (); Child.prototype.c
In object-oriented programming JS script, there are two main ways to define instance methods
As follows:
function ListCommon2 (Afirst)
{
var first=afirst;
This.do1=function ()
{
alert (' +first ');
}
Listcommon2.prototype.do2=function ()
{
// alert ("+first")//error, no access to the A-
this.do1 () ;
}
What's the difference between this.do1=function () and listcommon2.proto
This example describes the implementation of the prototype attribute in JavaScript to add a new method to a built-in object. Share to everyone for your reference. The implementation methods are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24-25
I hope this article will help you with your
I have always been very familiar with JavaScript, because I will only learn it when it is used in actual projects.For details about the propertype attribute in JS, refer to W3C. The prototype attribute allows you to add attributes and methods to an object. This is a magical saying. I have also referred to the design mechanism of the js inheritance idea, and it se
From: JavaEye.comPrototype provides a JavaScript object-oriented infrastructure, which can be used for object-oriented programming. The method for defining object types is as follows: var Person = Class. create ();Person. prototype = {Initialize: function (name, age ){This.
From:JavaEye.com prototype provides a JavaScript object-oriented infrastructure that we can use for object-oriented programming, defining object types in the following ways:
var person = class.create ();Person.prototype = {initialize:function (name, age) {this.name = name;Th
From:JavaEye.com
Prototype provides a JavaScript object-oriented infrastructure that we can use for object-oriented programming, defining object types in the following ways:
var person = class.create ();
Person.prototype = {
Initialize:function (name, age) {
THIS
An element is added to the obj1 array, which is also added in the Obj2 array.Do they inherit the array as a pointer? Everyone has an array of prototype this object?
//最后问一个很奇怪的问题(prototype中的array难道也只是一个指针?)
Thank you..
Reply content:
An element is added to the obj1 array, which is also added in the Obj2 array.Do they inherit the array as a pointer? Everyone
has been using JS to write self-righteous object-oriented approach, encountered a problem, is to define a method, as follows:
function ListCommon2 (First,second,third)
{this
. First=function ()
{
alert (' +first ');
}
Listcommon2.do1=function (a)
{
//this . A ();
Alert ("the" +first);
}
Listcommon2.prototype.do2=function (a)
{
//this. A ();
Alert ("the" +first);
}
What is the difference b
This article mainly introduces the prototype chain inheritance of js Object Inheritance, analyzes the implementation methods and precautions of prototype chain inheritance in the form of instances, and has some reference value, for more information about how to use prototype chain inheritance of js
A common way to create custom types is to use the constructor pattern in combination with the prototype pattern.
The constructor pattern is used to define the specific parts (properties and methods) of the instance object, and the prototype pattern is used to define the shared part.
This saves the maximum memory overhead.
function Human (name, sex) { this.nam
Two common methods are JS inheritance and object-oriented writing.
1. Prototype inheritance
Use prototype to bind an object.
During inheritance, use call in the subclass to inherit the constructor of the parent class, and use new to declare the method that inherits the parent class.
var DemoParent = function (param1,
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.