Programming Assistant JavaScript Learning Library-object-oriented programming notes __ algorithm

Source: Internet
Author: User

Disclaimer: This article originates from the JavaScript Learning Library prototype object of the programming helper app, which defines the properties and methods shared by all instance objects, so it is also referred to as the prototype of the instance object, which can be viewed as deriving from the prototype object. A constructor is a function and also an object, and all constructors have prototype attributes (in fact, all functions have prototype properties), so all objects have their own prototype prototype object. The object system of the JavaScript language is not based on "class", but on constructors (constructor) and prototype chains (prototype) because the value of the original type is not an object, the instanceof operator cannot be used to determine the type.
With the instanceof operator, you can also skillfully resolve the problem of adding a new command when calling a constructor.

function Fubar (foo, bar) {
  if (this instanceof fubar) {
    this._foo = foo;
    This._bar = bar;
  }
  else return to New Fubar (foo, bar);
The This in the constructor refers to the instance object. Find the largest element of an array
JavaScript does not provide a function to find the largest element of an array. Using the Apply method and the Math.max method, you can return the largest element of an array.
var a = [2, 4, 9];
Math.max.apply (null, a)
//output is 15
All properties of the object itself can be obtained by using the Object.getownpropertynames method. The properties of the object itself, some of which can be enumerated (enumerable), and some cannot be enumerated. Get only those properties that can be enumerated, using the Object.keys method. If the call method or the Apply method has no arguments, or if the parameter is null or undefined, it is equivalent to pointing to the global object.
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.