Js-----var x, this.x, x....inheritance
2010-01-27 19:05
423 查看
In JavaScript area,,,as far as I know, The JavaScript execution context is a concept that explains much of the behavior of JavaScript functions. The execution context represents the environment in which a piece of JavaScript code executes. JavaScript knows of three execution contexts:
The global execution context is the implicit environment (context) in which the JavaScript code that is not part of any function executes.
The function execution context is the context in which the code of a function executes. A function context is created automatically when a function is executed, and removed from the contexts stack afterwards.
The eval() execution context is the context in which JavaScript code executed using the eval( ) function runs.
The scope of the global execution context contains the locally defned variables and unctions, and the browser's window object. In that context, this is equivalent to window, so you can access, for example, the location property of that object using either this. location or window. location.
The scope of a function execution context contains the function's parameters, the locally defned variables and functions, and the variables and functions in the scope
of the calling code. This explains why the getCellCount( ) function has access to the _rows and _columns variables that are defned in the outer function (Table):
// Table class
function Table (rows, columns)
{
// save parameter values to local variables
var _rows = rows;
var _columns = columns;
// return the number of table cells
this. getCellCount = function()
{
return _rows * _columns;
} ;
}
The scope of the eval() execution context is identical to the scope of the calling code context. The getCellCount( ) function from the above code snippet could be written like this, without losing its functionality:
// return the number of table cells
this. getCellCount = function ()
{
return eval(_rows * _columns) ;
} ;
var x, this.x, and x:
Actually, I think object of JavaScript is similar with Association Array. we can declare a object as this:
代码
function Drive(){
alert('Drive in Car');
}
function car(name){
this.Name = name;
this.drive = Drive;
}
function BenCar(name){
this.inheritanceCar = car;
this.inheritanceCar(name);
this.fly=Fly;
}
function Fly(){
alert('Fly in BenCar')
}
var obj = new BenCar("Demo");
obj.drive();
obj.fly();
However, if we do as above shows. I think it will generate many functions in Global Execute Context. And it will result in Naming Collision. Thus we can use the Prototype feature of JavaScript to instead.
The global execution context is the implicit environment (context) in which the JavaScript code that is not part of any function executes.
The function execution context is the context in which the code of a function executes. A function context is created automatically when a function is executed, and removed from the contexts stack afterwards.
The eval() execution context is the context in which JavaScript code executed using the eval( ) function runs.
The scope of the global execution context contains the locally defned variables and unctions, and the browser's window object. In that context, this is equivalent to window, so you can access, for example, the location property of that object using either this. location or window. location.
The scope of a function execution context contains the function's parameters, the locally defned variables and functions, and the variables and functions in the scope
of the calling code. This explains why the getCellCount( ) function has access to the _rows and _columns variables that are defned in the outer function (Table):
// Table class
function Table (rows, columns)
{
// save parameter values to local variables
var _rows = rows;
var _columns = columns;
// return the number of table cells
this. getCellCount = function()
{
return _rows * _columns;
} ;
}
The scope of the eval() execution context is identical to the scope of the calling code context. The getCellCount( ) function from the above code snippet could be written like this, without losing its functionality:
// return the number of table cells
this. getCellCount = function ()
{
return eval(_rows * _columns) ;
} ;
var x, this.x, and x:
Actually, I think object of JavaScript is similar with Association Array. we can declare a object as this:
代码
function Drive(){
alert('Drive in Car');
}
function car(name){
this.Name = name;
this.drive = Drive;
}
function BenCar(name){
this.inheritanceCar = car;
this.inheritanceCar(name);
this.fly=Fly;
}
function Fly(){
alert('Fly in BenCar')
}
var obj = new BenCar("Demo");
obj.drive();
obj.fly();
However, if we do as above shows. I think it will generate many functions in Global Execute Context. And it will result in Naming Collision. Thus we can use the Prototype feature of JavaScript to instead.
相关文章推荐
- Options ExecCGI is off in this directory: /var/www/cgi-bin/pipeWeb-bin/pipe_login.pl,
- JS全局变量VAR和THIS--在函数内部,加var是局部变量,不加是全局变量
- js常见的var that = this的用法
- js中用this,var,let 声明的变量的区别
- 慎用 JS 中的 for (var index in items) 循环数组项
- JS全局变量var与this
- angular this vs $scope (How does 'this' and $scope work in AngularJS controllers?)
- js中var self=this的解释
- JS面向对象(2) -- this的使用,对象之间的赋值,for...in语句,delete使用,成员方法,json对象的使用,prototype的使用,原型继承与原型链
- js中的this和var里面的文章
- Angular build Error:In this configuration Angular requires Zone.js
- 为什么在js中要写var this =that?
- JS var self =this
- JS全局变量VAR和THIS
- JS中var self =this; 或者 JS var _this =this;
- js中var self=this的解释
- js中的this & var, function & object, prototype & apply
- js中,一个js中的函数,第一句var thiz = this; 为什么要这样做?
- javascript中,一个js中的函数,第一句var _this = this;为什么要这样做?
- Note on <AngularJS> - Aborted Because Of Too Many Errors In This Book