Discover object prototype hasownproperty call, include the articles, news, trends, analysis and practical advice about object prototype hasownproperty call on alibabacloud.com
Ranges represent an interval of values. The value type just needs to be "compatible," that is, to implement a succ method letting us step from one value to the next (its successor ).
Prototype provides such a method for number and string, but you are of course welcome to implement useful semantics in your own objects, in order to enable ranges based on them.
The objectrange object basically implements
First, we can look at what we usually use var ' Hello ' ; Alert (typeof str); // string var New String ("hello"); Alert (typeof str); // ObjectThe above one represents the base type string, which is the object type (String object type).However, even though it is a string basic type, you can still call Charat and other methodsvar ' Hello ' ; Str
7.3 complete solution
Developers of Sunny decided to use the prototype mode to quickly create work weekly reports, as shown in figure 7-3:
Figure 7-3 create a weekly report structure
In Figure 7-3, weeklylog acts as the prototype, the object class acts as the abstract prototype, and the clone () method is the
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 between objects, and Information Hiding exis
Look at the following example:1 varA={2X:2,3GetNumber:function(z) {4 return This. x+ This. y+Z;5 } 6 } ; 7 8 9 varb={TenY:23, One __proto__:a; A //indicates that object B inherits to the object A;__proto__ property to suppress the property for the object itself - } ; - theB.getnumber (4);//OutputIf you
, 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
The Template object here is actually a tool for formatting strings, just like the String. format method in java. This object provides only one evaluate method.
The Code is as follows:
Var Template = Class. create ({// Initialization MethodInitialize: function (template, pattern ){This. template = template. toString ();This. pattern = pattern | Template. Pattern;},// The formatting method. For java, it is
CopyCode The Code is as follows: object. Extend (number. prototype, (function (){
// Returns the hexadecimal color.Function tocolorpart (){Return this. topaddedstring (2, 16 );}
// Returns the next continuous value.Function succ (){Return this + 1;}
// Perform an operation consecutivelyFunction times (iterator, context ){$ R (0, this, true). Each (iterator, context );Return this;}
// Returns a fix
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 between objects, and information hiding exis
Copy Code code as follows:
var Template = class.create ({
Initialization method
Initialize:function (template, pattern) {
This.template = Template.tostring ();
This.pattern = Pattern | | Template.pattern;
},
Formatting method, if from the Java point of view, actually called format is better:)
Evaluate:function (object) {
Check to see if the Totemplatereplacements method is defined, so call th
unacceptable. Indeed, you cannot apply an operation to a null ruling, but the result is:
Such
It runs well.
Now we have written this code.
struct t { int m_value;};void info(const t *p) { cout
This section is written in the main function.
int main(){// T *p = NULL;// p->info();// p->printValue(); t *p2 = NULL; info(p2);// cout
In fact, these two have already understood the prototype of the C ++
Copy codeThe Code is as follows:Var Template = Class. create ({// Initialization MethodInitialize: function (template, pattern ){This. template = template. toString ();This. pattern = pattern | Template. Pattern;},// The formatting method. For java, it is actually better to call format :)Evaluate: function (object ){// Check whether the toTemplateReplacements method is defined. If yes,
CopyCode The Code is as follows: var template = Class. Create ({
// Initialization Method
Initialize: function (template, pattern ){
This. template = template. tostring ();
This. pattern = pattern | template. pattern;
},
// The formatting method. For Java, the format is actually better.Evaluate: function (object ){// Check whether the totemplatereplacements method is defined. If yes, call// In the entir
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 paren
');
ControlUI.style.backgroundColor = ' white ';
}
The result is still a failure
And then I figured it out, I guess that's it.
Copy Code code as follows:
MenuControl.prototype.controlUI.style.backgroundColor = "white"; I'll give you a value, see where you run.
MenuControl.prototype.show = function () {
This.controlUI.style.backgroundColor = ' #DDDDDD ';
};
function Menucontrol (controldiv, map) {
Controlui = document.createelement (' div ');
This.control
Today, we will focus on the object-oriented content of javascript: object literal, this, this, call () and apply () methods, and JS exception handling.
Object literal:
1. The examples we have seen earlier use dot identifiers to create objects and members. For example:
var temp=document.getElementById('example');
We u
properties.Example 5: an inherited demo1As can be seen from the above example, extend can inherit the methods and properties of base after call.By the way, using apply in the JavaScript framework prototype creates a schema that defines the class, with the following implementation code:1 var Class = {2 function () {3 returnfunction () {4 this. initialize.apply (this, arguments); 5 }6 }7 }Parsing: From the code perspective, the
: false, configurable: true.
The value of the length property of the Function prototype object is 0.
MethodFunction.prototype.call (thisarg[, arg1[, arg2[, ...])A method that applies another object in the context of an object thisarg; A parameter can be passed in as a list, that is, a function or method is cal
:
(Function (form parameter) {function body}) wraps an anonymous function in brackets so that it is equivalent to a "noun" for other parts of the Code ".
Therefore, reference:
(Function (form parameter) {function body}) (real parameter) and the above most common reference:
Function names (real parameters) are easy to understand. They define an anonymous function and call it immediately. Reference:
C = (function (which) {return function (num) {alert (
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.