this.prmtr = prmtr 有什么意义?
What is the point of this.prmtr = prmtr?
在每一个游戏教程中我都会遇到这样的代码语句:
function example(parameter) {
/*What does this do?*/
this.parameter = parameter;
//and:
this.parameterTwo = function() { /*code*/};
}
这有什么意义?
相当宽泛的问题,但基本上你是在创建一个函数并将数据传递给它。您可以将传入的参数设置为附加(通过 this.
)到您使用 'new' 关键字创建的函数实例的变量。然后你可以对这些附加变量进行操作,或者在我们的例子中使用函数 parameterTwo
,你可以让它做一些事情,比如 return 传入的内容并添加一个 '!'对它...
function example(parameter){
this.parameter = parameter;
this.parameterTwo = function(){return this.parameter + "!";}
}
var game = new example("hello");
console.log(game.parameterTwo());
在每一个游戏教程中我都会遇到这样的代码语句:
function example(parameter) {
/*What does this do?*/
this.parameter = parameter;
//and:
this.parameterTwo = function() { /*code*/};
}
这有什么意义?
相当宽泛的问题,但基本上你是在创建一个函数并将数据传递给它。您可以将传入的参数设置为附加(通过 this.
)到您使用 'new' 关键字创建的函数实例的变量。然后你可以对这些附加变量进行操作,或者在我们的例子中使用函数 parameterTwo
,你可以让它做一些事情,比如 return 传入的内容并添加一个 '!'对它...
function example(parameter){
this.parameter = parameter;
this.parameterTwo = function(){return this.parameter + "!";}
}
var game = new example("hello");
console.log(game.parameterTwo());