从方法中调用方法 [英] calling a method from a method

查看:76
本文介绍了从方法中调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个带有多种方法的函数。为简单起见,它看起来有点像这样:

super.prototype.aProperty =" HELLO";

super.prototype.returnValue = function(){


返回2;


}


super.prototype.aMethod = function(){$ / $

var a = this.returnValue()

alert(a)


}


函数super(){}

theObject = new super;


theObject.aMethod( );


如何在方法中调用方法?换句话说,我如何才能使bb成为这个。关键字引用对象而不是方法吗?


Tor

Hi

I have a a function with several methods. For simplicity it looks a bit
like this:
super.prototype.aProperty="HELLO";
super.prototype.returnValue = function () {

return 2;

}

super.prototype.aMethod = function () {

var a = this.returnValue()
alert(a)

}

function super() { }

theObject= new super;

theObject.aMethod();

How can I call a method from within a method? In other word how can I
make the "this" keyword refere to the object and not the method?

Tor

推荐答案

2006 -04-21 17:10:09 +0200,torbs <到******** @ gmail.com>说:
On 2006-04-21 17:10:09 +0200, "torbs" <to********@gmail.com> said:


我有一个带有几种方法的函数。为简单起见,它看起来有点像这样:

super.prototype.aProperty =" HELLO";
super.prototype.returnValue = function(){

返回2;

}

super.prototype.aMethod = function(){

var a = this.returnValue()
提醒(一)


函数super(){}


你应该写构造函数声明_before_为其原型分配任何

。此外,JavaScript中的类名传统上以b $ b开头。

你绝对不应该将函数命名为super。因为它是一个

保留字。

theObject = new super;


你必须打电话给构造函数:

theObject = new Super()


不仅仅是写下它的名字。

theObject.aMethod();

如何在方法中调用方法?换句话说,我怎么能做出这个呢?关键字引用对象而不是方法?


默认情况下,这实际上是指方法的拥有者,所以你很幸运,你不需要做任何事情来实现结果。

但是你不能引用方法所有者的所有者,因为

实例,除非你设置了一个属性来引用它。 br />
Tor
Hi

I have a a function with several methods. For simplicity it looks a bit
like this:
super.prototype.aProperty="HELLO";
super.prototype.returnValue = function () {

return 2;

}

super.prototype.aMethod = function () {

var a = this.returnValue()
alert(a)

}

function super() { }
you should write the constructor declaration _before_ assigning anyting
to its prototype. Moreover, class names in JavaScript traditionnally
begin with a capital.
And you should definitely NOT name a function "super" since it is a
reserved word.
theObject= new super;
you must call the constructor :

theObject = new Super()

not just write its name.
theObject.aMethod();

How can I call a method from within a method? In other word how can I
make the "this" keyword refere to the object and not the method?
by default, this actually refers to the owner of the method, so you''re
lucky, you don"t have to do anything to achieve that result.
However you can''t refer to the owner of the owner of the method, for
instance, unless you have set a property to reference it.

Tor



-

David Junger


--
David Junger


谢谢!


事实证明这不是我的问题,但我会为此创建一个

mnew帖子。


Tor

Thank you!

As it turns out this was not really my problem, but I will create a
mnew post for that.

Tor


Touffy写道:
Touffy wrote:
2006-04-21 17: 10:09 +0200,torbs <到******** @ gmail.com>说:
On 2006-04-21 17:10:09 +0200, "torbs" <to********@gmail.com> said:
我有一个带有几种方法的函数。为简单起见,它看起来有点像这样:

super.prototype.aProperty =" HELLO";
super.prototype.returnValue = function(){

返回2;

}

super.prototype.aMethod = function(){

var a = this.returnValue()
提醒(一)


函数super(){}
你应该写一下构造函数声明_before_赋予它任何
原型。
I have a a function with several methods. For simplicity it looks a bit
like this:

super.prototype.aProperty="HELLO";
super.prototype.returnValue = function () {

return 2;

}

super.prototype.aMethod = function () {

var a = this.returnValue()
alert(a)

}

function super() { }
you should write the constructor declaration _before_ assigning anyting
to its prototype.




我曾经也这么认为,但事实上,订单并不重要

这里因为变量实例化在执行之前发生。

此外,JavaScript中的类名传统上以大写字母开头。


传统上,JavaScript中没有类。它是一种基于原型的继承的编程

语言。但从这个意义上来说,这个陈述是正确的:
:构造函数应该有一个以大写字母开头的标识符,以便将它们与其他方法区分开来。

你绝对不应该将功能称为超级功能。因为它是一个保留字。



I once thought so, too, but in fact, the order is not significant
here as variable instantiation takes place before execution.
Moreover, class names in JavaScript traditionnally begin with a capital.
Traditionally, there are no classes in JavaScript. It is a programming
language with prototype-based inheritance. But the statement holds true
in that sense: constructors should have identifiers that start with a
capital letter to distinguish them from other methods easily.
And you should definitely NOT name a function "super" since it is a
reserved word.




True。



True.

theObject = new super;
theObject= new super;


你必须调用构造函数:

theObject = new Super()
不只是写出它的名字。



you must call the constructor :

theObject = new Super()
not just write its name.




忽略大小写,两个语句在语义上都是等价的。

PointedEars



Ignoring the case, both statements are semantically equivalent.
PointedEars


这篇关于从方法中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆