this for function context
this is a reference to the context object that the function is operating on.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
window.color = "A";
var o = { color: "B" };
function sayColor(){
document.writeln(this.color);
}
sayColor(); //A
o.sayColor = sayColor;
o.sayColor(); //B
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Essential Types
JavaScript Book
Essential Types
Function:
- The Function Type
- Function Declarations versus Function Expressions
- Functions as Values
- Returning a function from a function
- Function arguments
- this for function context
- Function caller
- Function length property
- Function apply()
- Function.call() method
- Function's bind() method
- Function toLocaleString() and toString()