The summary of the--javascript of the front-end development face (II.) __javascript

Source: Internet
Author: User

Http://www.jianshu.com/p/1a20dac12cf6

Related knowledge points

Data types, operations, objects, function, inheritance, closures, scopes, prototype chains, events, REGEXP, JSON, Ajax, DOM, BOM, memory leaks, Cross-domain, asynchronous loading, template engine, front-end MVC, front-end MVVM, routing, modularity, Http, Canvas, JQuery, ECMAScript 2015 (ES6), Node.js, Angularjs, Vue, react ... Topics & Answers documen.write and innerHTML differences

document.write only the entire page
innerHTML can redraw part of the page
What the browser detects through.
(1) navigator.useragent
(2) The characteristics of different browsers, such as AddEventListener
What kinds of data types are JavaScript.
Simple, number,boolean,string,null,undefined
compound, object,array,function
Intercepts the "Fghi" of the string "Abcdefghi"
var myvalue= "Abcdefghi";
var jiequ=myvalue.substring (myvalue.length-4,myvalue.length);
alert (jiequ);
-Write down the result of the operation
Alert (typeof (null)); Object
alert (typeof (undefined));//undefined
alert (typeof (NaN));//number
alert (nan==undefined);// False
alert (Nan==nan);//False
var str= "123abc";
Alert (typeof (str++)); Number
alert (str);//NaN
Q What is the value of x, Y, and Z after the execution is completed?
var x = 1, y = z = 0;
function Add (n) {
  n = n+1;
}
y = Add (x);
function Add (n) {
  n = n + 3;
}
z = Add (x);
1, Undefined, undefined
How do I prevent events from bubbling?
Method function to block bubbling
stoppp (e)
{
  var    evt = e| | window.event;
  ie use CANCELBUBBLE=TRUE to block and FF under the need to use Stoppropagation method
  evt.stoppropagation? Evt.stoppropagation (): ( evt.cancelbubble=true);
}
Write out the results of the program running?
For (Var i=0, j=0 i<10, j<6; i++, J + +) {
  k = i + j;
}
10
Write a method to find the byte length of a string
/* Suppose: an English character occupies a byte, a Chinese character occupies two bytes
/function getBytes (str) {
  var len = str.length,
      bytes = Len,
      i = 0;
  for (; i<len; i++) {
      if (str.charcodeat (i) > 255) bytes++;
  }
  return bytes;
}
Alert (GetBytes ("Play, as"));
How to make a deep clone of an object in JavaScript.
function Cloneobject (o) {
  if!o | | ' Object '!== typeof o) {return
      o;
  }
  var c = ' function ' = = typeof O.pop? [] : {};
  var p, v;
  For (P in O) {
      if (O.hasownproperty (p)) {
          v = o[p];
          if (v && ' object ' = = typeof v) {
              c[p] = Ext.ux.clone (v);
          }
          else {
              C[p] = v;
  }} return c;
};
How to control line wrapping in alert.
\ alert ("P\NP");
Write a JavaScript function parsequerystring, which is used to parse the URL parameter into an object, such as:
var url = "http://witmax.cn/index.php?key0=0&key1=1&key2=2″;
function parsequerystring (URL) {
  var params = {},
      arr = Url.split ("?");
  if (arr.length <= 1) return
      params;
  arr = Arr[1].split ("&");
  For (var i=0, l=arr.length; i<l; i++) {
      var a = arr[i].split ("=");
      Params[a[0]] = a[1];
  }
  return params;
}
var url = "http://witmax.cn/index.php?key0=0&key1=1&key2=2",
  PS = parsequerystring (URL);
Console.log (ps["Key1"]);
How do you control the amount of data that a Web page can transmit over the network?
Enable gzip compression
keep good programming habits, avoid duplicate css,javascript code, extra HTML tags and attributes
The following code runs the results
function say () {
 //local variable which ends up within closure
 var num = 888;
 var sayalert = function () {alert (num);}
 num++;
 return sayalert;
}
var Sayalert = Say ();
Sayalert ();//889
Please implement the object.getprototypeof () function in ECMAScript 5
function Proto (object) {return
  !object?                Null
      : ' __proto__ ' in object?  object.__proto__
      :/* not exposed? */      Object.constructor.prototype
}
How to achieve Array.prototype.forEach.
if (! Array.prototype.forEach) {
  Array.prototype.forEach = function (fn) {for
      (var i = 0; i < this.length; i++) {
  FN (This[i], I, this);
}} ["A", "B", "C"].foreach (function (value, index, array) {
  assert (value, "is in position" + Index + "out of" + (array . length-1));
How to convert arguments to an array.
Object.prototype.slice.call (arguments);
The following program runs the results.
var ninja = function Myninja () {
  alert (ninja = = Myninja);
Ninja ();
Myninja ();
True, error (Error-myninja is not defined.)
How to get the horizontal position of the cursor.
function GetX (e) {
  e = e | | window.event;
  First check non IE browser, check IE position return
  E.pagex | | e.clentx + document.body.scrollLeft;
}
Browser-compatible method to get the Style property (name) of the specified element (elem)
function GetStyle (elem, name) {if
  (Elem.style[name]) {//If the property exists in style[], take direct return
      elem.style[name];
}
else if (Elem.currentstyle) {//otherwise try IE method return
      elem.currentstyle[name];
} Try the way of the consortium
else if (Document.defaultview && document.defaultView.getComputedStyle) { 
      name = Name.replace ([[A-z])/g, "-$1"), TextAlign style in//w3c, text-align
      name = Name.tolowercase ();
      var s = document.defaultView.getComputedStyle (Elem, "");
      return s && s.getpropertyvalue (name);
  else{return
      null;
  }
PHP-like Print_r functions implemented in JavaScript
function Print_r (theobj) {
  var retstr = ';
   if (typeof theobj = = ' object ') {
        retstr + = ' <div style= ' font-family:tahoma; font-size:7pt; " > ';
        For (var p in theobj) {
              if (typeof theobj[p] = = ' object ') {
                    retstr + = ' <div><b>[' +p+ '] => ' + typeof (theobj) + ' </b></div> ';
                    Retstr = ' <div style= ' padding-left:25px; > ' +  print_r (theobj[p]) + ' </div> ';
              } else {
                    retstr + = ' <div>[' +p+ '] => <b> ' + theobj [P] +  ' </b></div> ';
              }  
         }
        Retstr + = ' </div> ';
    }
    return  retstr;
}
The following program runs the results.
var B = parseint ("01"); Alert (
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.