1. What is the function?
First, look at the data type -------------------- data type introduced article
- Basic data types : numeric (number), string (string), Boolean (Boolean), null, undefined
- Complex data types : an object (object), the constructor (function), the array (Array), etc.
- Complex data type called reference data types
Function is a complex data types , it is stored in a stack inside the address stored in the stack inside the data
The concept of functions
For js, the function is arbitrary piece of code in a box inside
When I want to make this code is executed, direct the implementation of the box inside the code on the line
javascript authoritative guide explains:
function (function): function is a JavaScript snippet with the name (named) and parameters can be defined once many times transfer
2. What is the method?
The conceptual approach
javascript authoritative guide explains:
method (method): When the function and objects co-wrote together, function becomes a "method" (method) // When the function assigned to the object's attributes, we called the "method"
- Object :
- JavaScript, everything is an object: strings, numbers, arrays, dates, and so on.
- In JavaScript, the object is to have the properties and methods of data.
var obj = {
name : '张三',
age : 18
}
Functions and objects co-wrote together
var obj = {
name : '张三',
age : 18
fun : function(){
console.log(this.name) //这里的this指向的是obj这个对象
}//fun就成了该对象的一个方法
}
或者这样
var abc = function(){
......
}
3. The difference between the functions and methods
The functions and methods are essentially the same, but the method is a special case function is a function of the value assigned to the objects
The method is also a function, but rather special