Emmachen / SapUi5Test

1 stars 1 forks source link

调试的时候一直有一个metadata出来 #8

Closed ghost closed 8 years ago

ghost commented 8 years ago

调试的时候一直有一个metadata出来

Answered by Jerry

看这个:

You have one variable which points to a button control instance, for example "oButton". You type "oButton." in Chrome console, and you will see lots of functions in auto-complete list. You want to know by which rules are these functions chosen to display here, and where do they come from? See answer here.

Emmachen commented 8 years ago

师父,我看了你的关于metadata的连接,事实上,当我刚开始对此感到疑惑的并不是metadata的内容,而是,what is metadata exactly? 经过这些天的调试过程也对the prototype chain,子类如何调用父类的方法,获取属性,有了一定的了解。例如,实例button的时候,前面的类都是在调用父类的方法,到了最底层的类,就是Metadata.createClass.来创建类 image 展开button节点,proto: element--managedObject--eventProvider----metadata.createClass 展开button.getMetadata(),返回的类型是elementMetadata. see the parent: elementMetadata--managedObjectMetadata-metadata--metadata however when the steroType is object,then the oPanret is just metada, image is metadata set for class? I'm wondering if someone asks that what is metadata, how will you anwser that?

ghost commented 8 years ago

Hi Wenxin,

上面的截图里虽然说_oClass, 但实际上JavaScript里是没有原生的class这个概念哈,仅有object和object的prototype这些概念用于实现属性和方法的继承。

关于metadata,你可以先看这两个link:

举个例子:比如一个人简历里描述自己从大一到大四上了哪些专业课,做了哪些实习,这种描述具体activity的数据,称之为transactional data. 而一个人简历里给出的自己姓名,年龄,性别,家庭住址,联系电话等等,这些数据都是用来描述这个人的属性,这种属性在很长一段时间内不会发生变化,我们称这些数据为描述这个人的“metadata”.

metadata有两个用途了,第一个就是你在UI5里学到的,用于继承。Parent里定义了metadata后,child就无需重复定义,直接继承拿过来用。这就是为什么你有一个button控件的instance oButton,你在console里敲了oButton.之后,点号后面出现一大堆方法。这些方法都是这个button原型链上的其他parent的metadata里包含的。

第二个用途,就是被SAP的各种框架消费,自动生成各种各样的其他东西。这个你以后会学到。