JS Micro Professional Homework Answer

Source: Internet
Author: User

function type (obj) {    return Object.prototype.toString.call (obj). Slice (8,-1). toLowerCase ()}

The implementation of the type function is used to identify standard types and built-in object types, with the following syntax:

var t = type (obj);

Examples of use are:

  1. var t = Type (1) //t=== "number"
  2. var t = Type (new number (1)) //t=== "number"
  3. var t = Type ("abc") //t=== "string"
  4. var t = Type (new String ("abc")) //t=== "string"
  5. var t = Type (true) //t=== "boolean"
  6. var t = type (undefined) //t=== "undefined"
  7. var t = type (null) //t=== "null"
  8. var t = Type ({}) //t=== "Object"
  9. var t = Type ([]) //t=== "array"
  10. var t = Type (new date) //t=== "Date"
  11. var t = Type (/\d/) //t=== "RegExp"
  12. var t = Type (function() {}) //t=== "function"

The Object.create (proto) method, defined in ES5, creates and returns a new object that is prototyped with the incoming proto object.

The syntax is as follows:

Object.create (Proto) (note: The second parameter is ignored)

proto--as a prototype object for newly created objects

Examples of use are:

var a = Object.create ({x:1, y:2});

    function (obj) {    varfunction() {};     = obj;     return New F ();}

Object.create is not supported in some browsers, please give the Object.create compatible implementation.

function (obj) {    varThis,        = arguments;     return function () {        1)    }}

function Fibonacci (n) {    if (n = = 0)        {return 0;     Else if (n = = 1)        {return 1;     Else {        return (Arguments.callee (n-1) + Arguments.callee (n-2));}    }

functionSearch (ARR,DST) {varType = Object.prototype.toString.call (arr). Slice (8,-1); if(Type! = ' Array '){        ThrowTypeError (' Object prototype may only is an Array ')    }    varLen =arr.length; if( !Len) {        return-1; }     varL = 0; varH = len-1;  while(L <=h) {        varm = Math.floor ((h+l)/2);if(Arr[m] = =DST) {            returnm; }Else if(DST < arr[m]) {//left Half partH = m-1; }Else{//Right Half partL = m + 1; }     }}vararr = [1,2,4,6,7,9,19,20,30,40,45,47];alert (arr,45))

JS Micro Professional Homework Answer

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.