When I call this class definition, it calls init, init and I give it an x and a y value.
我说过,当我们,调用这个类的定义的时候,它会去调用。
It's got this funky looking form, right, it says, I've got something that I'm going to call a class, got that key word class right here.
以及我们怎么来使用这些方法,因此我要回到类这个概念上来,让我们来建立第一个类吧,就在你们课堂手册的这儿,我会去定义一个类。
When I try and evaluate that expression of greater than, is going to go into the class to say greater than is a comp method.
这个大于的操作符的时候,是到类的定义里去识别,大于是一个比较的方法,那么让我在这里说仔细一点吧。
c point You can see inside of it, it's got a set of definitions for things like functions.
我会把它简短的命名为,你可以看到类的里面,有一个对于函数之类的东西的定义集。
Is is essentially saying, given 2 things, do they point to exactly the same referent?
或者换种思考的方式,大家记得我说过当我们,调用类的定义声明的时候,它会创建一个实例?
Again, I could have some other functions to compute things, but this is typically the place where I'm going to put them in.
注意这个声明典型的行为,就是为了定义了内部变量,以及类的内部特性,在说一次,我可以写一些。
Right now it's empty, actually it's not quite empty, it has a pointer back to the class.
当我调用了这个类的,定义声明的时候,它在内存中的特定点。
And is able to then say, inside of that class definition, find the value of x.
这个类的定义这里然后取值,也可以这么说,在类的定义的里面。
OK, the reason I'm saying this is, we have one class definition, is a cookie cutter, it's a template that's going to let us build versions of these things.
同一实例,好,我为什么要说这个的原因是,我们学习了类的定义了,这就像曲奇成型刀一样,它是个让我们建立不同版本的,这些东西的一个模板。
But in particular, it's going to use self to refer to that instance.
好,那么让我换种,稍微不同的说法吧,我有一个类的定义。
What did I just do there?
我在我的类的定义里面定义的东西之一?
It's actually an object somewhere.
当我调用这个类的定义的时候。
I don't have to put an init in, but it's again, usually a good idea to put that in originally.
类定义内做些什么其他的东西呢?,好,在两个例子里,我都有init声明。
That's a bad mistake.
我说错了,当我调用类的定义。
So another way saying it again is, when I call the class definition, by default I'm going to look to see is there an init method there, and if there is, I'm going to use it.
当我调用类的定义,默认的是语言要去查看,是不是有个init的方法,如果有的话,程序就会调用它,按照惯例。
应用推荐