Home > Web Front-end > JS Tutorial > How to use the Function function for getting started with js

How to use the Function function for getting started with js

高洛峰
Release: 2017-01-04 16:04:06
Original
1835 people have browsed it

In JavaScript, functions can be nested.

For example:

function(){
 
  funcrion square(x){ return x*x; }
 
  return square(10); 
 
}
Copy after login

In JavaScript, a function is bound to an object. The function called by the object is called a method. It is easy to follow. C# is confusing.

1. Function attributes

In the function body, you can get the number of actual parameters passed into the function through arguments.length.

function fun1 (x,y){
 
  document.write(arguments.length());  //输出2,传入的参数是两个
}
fun1();
Copy after login

2. Bind the function to the object

var fun1 = function () {
 alert(this.name);
}
var o = { name:"张三",fn : fun1 };
o.fn();  //输出 张三
var o = { name: "张三", fn: function () { alert(this.name) } }
o.fn();  //输出张三
Copy after login

The above is this article All the content, I hope it will be helpful to everyone, thank you for your support to the PHP Chinese website!

For more articles related to how to use the Function function for getting started with js, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template