有人可以解释Polymer({
// ...
properties: {
value1: {
type: String,
value: '' // initialize for data binding
}
}
});
和getName()
如何在没有被告知的情况下最终引用与createProgressReport()相同的项目吗?
很明显,使用getGrade()
对数组中的项调用createProgressReport
。但似乎没有告诉item.createProgressReport()
和getName()
在同一项目上被调用,因为没有像getGrade()
这样的点符号。
item.getName()
和getName()
方法如何自动“知道”哪个学生可以调用该方法。
getGrade()
答案 0 :(得分:8)
createProgressReport
。除非您正在编写其他代码,否则将在同一对象上调用在该方法中调用的任何方法。
换句话说,你的方法相当于:
String myString = this.getName() + " " + this.getGrade();
答案 1 :(得分:2)
对我来说,你似乎是在班级的背景下工作。
在面向对象编程中,从类中的另一个方法调用方法通常会引用同一个实例。
可能无法以这种方式执行的语言是JavaScript或php,您需要引用$ this对象。
//php
$this->methodName();
//JavaScript
var self = this;
self.methodName();
//java
methodName(); //implied this when working within the context of the same class