admin管理员组文章数量:1302406
I'm relatively new in javaScript and I was doing some inheritance. I thought I know what prototype is but then i met with uber method. Now I don't know the difference between those two. I know that uber is like super in java and that's all. But then prototype is something that bothers me. If you can give me some simple example of using those two I would appreciate it very.
I'm relatively new in javaScript and I was doing some inheritance. I thought I know what prototype is but then i met with uber method. Now I don't know the difference between those two. I know that uber is like super in java and that's all. But then prototype is something that bothers me. If you can give me some simple example of using those two I would appreciate it very.
Share Improve this question asked Jan 14, 2015 at 11:07 anicicnanicicn 1935 silver badges15 bronze badges 4-
2
As far as I am aware, there is no
uber
method in JavaScript unless you're using a library which adds this method to objects. Are you using a library by any chance? – Qantas 94 Heavy Commented Jan 14, 2015 at 11:17 - Well I'm using one. It might be defined in it. But still I don't know the difference assuimng I know what uber is. It's just a pointer to a parent's object – anicicn Commented Jan 14, 2015 at 11:22
-
1
I've added an answer about the
uber
method Douglas Crockford uses in his inheritance tutorials assuming that you meant this. It seems to be the most popular example. Where exactly did you discoveruber
? – Alex Wolf Commented Jan 14, 2015 at 11:23 - I'm not sure Crockford is the best way to learn prototype as I've never seen him implement "classical inheritance" correctly. The following answer covers constructor functions and prototype: stackoverflow./a/16063711/1641941 hope it helps – HMR Commented Jan 15, 2015 at 1:26
1 Answer
Reset to default 12uber
is just a sugar method Douglas Crockford created in his examples of inheritance in JavaScript which should help the devoloper when working with the very, very flexible nature of JavaScripts prototypal inheritance.
This method doesn't exist in native JavaScript.
He explains the sugar methods he uses in detail here.
In his examples he defines the uber
method as a helper method to access the parent implementation of a method.
Let's assume that you have a "class" (I use this term to ease the example; strictly spoken there are no classes in JavaScript) Human
which has a walk
method. If you now "extend" this class in an Infant
class, you could overwrite walk
in such a way that the infant only crawls since it can't walk.
It's obviously not a great example but I hope you get the point.
In such a case you could use Douglas Crockfords uber
method to access the Human
implementation of walk
in the Infant
"class".
To pare JavaScripts native prototype
object and Douglas Crockfords uber
method would make no sense, since both serve pletly different purposes.
If you want more information on JavaScripts prototype
you can take a look at this question.
本文标签: Javascript difference between uber and prototypeStack Overflow
版权声明:本文标题:Javascript difference between uber and prototype - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741672502a2391686.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论