Java Basic Learning Experience 03

Source: Internet
Author: User

Function
    • The Name property of the function returns the names of the functions;
    • toStringthe use of a multi-line string can be implemented in disguise:
var multiline = function (fn) {  var arr = fn.toString().split(‘\n’);  return arr.slice(1, arr.length - 1).join(‘\n’);};function f() {/*  这是一个  多行注释*/}multiline(f);// “ 这是一个//   多行注释”
    • Note that for the var command, local variables can only be declared inside the function, declared in other chunks, and all are global variables;
    • The scope at which the function executes is the scope at which it was defined, not the scope at which it was called:
var a = 1;var x = function () {  console.log(a);};function f() {  var a = 2;  x();}f() // 1//很容易犯错的一点是,如果函数A调用函数B,却没考虑到函数B不会引用函数A的内部变量。var B = function () {  console.log(a);};function A(f) {  var a = 2;  f();}A(B)// ReferenceError: a is not defined
    • The runtime does not give an error, no matter how many parameters are supplied (or if no parameters are supplied). The value of the omitted parameter becomes undefined;
    • The length property of a function is independent of the number of arguments actually passed in, reflecting only the number of arguments the function expects to pass in.
    • Return cannot be used alone and must be used in a function;
    • The most common scenario for Eval is to parse the JSON data string, but the correct approach should be to use the native Json.parse method;
Strict mode andevalWith
    1. The external scope code cannot get eval the variables defined inside:
(function f() {  ‘use strict’;  eval(‘var foo = 123’);  console.log(foo);  // ReferenceError: foo is not defined})()
    1. But eval the values of variables that can read and write to the external scope:
(function f() {  ‘use strict’;  var foo = 1;  eval(‘foo = 2’);  console.log(foo);  // 2})()
    • In order to ensure that eval aliases do not affect code optimization, JAVASCRIPT standards stipulate that all aliases eval are performed with eval an internal global scope:
//下面这些形式都是eval的别名调用,作用域都是全局作用域。eval.call(null, ‘…’)window.eval(‘…’)(1, eval)(‘…’)(eval, eval)(‘…’)

Java Basic Learning experience

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.