首页 \ 问答 \ 实现接口和对象(Implementing Interfaces and Objects)

实现接口和对象(Implementing Interfaces and Objects)

当一个类实现一个接口时,是否使得从该类实例化的对象被视为该接口的对象?

即在一个实现Runnable接口的类上,是否使得从该类创建的实例被称为Runnable对象?

因此,在期望Runnable对象引用变量的地方(比如,在方法或构造函数的参数中),为什么我们可以提供该类的实例作为该方法或构造函数的参数是合法的? 是否因为通过实现接口,类本质上是接口的一个对象?


When a class implements an interface, does that make objects instantiated from the class be perceived as an object of that Interface?

i.e. Upon a class implementing the Runnable interface, does that make instances created from that class to be called a Runnable object?

So, where a Runnable object reference variable is expected (say, in the parameter of a method or a constructor), why is it legal that we can provide an instance of the class as an argument to that method or constructor? Is it because by implementing the interface, the class, is in essence, an object of the Interface?


原文:https://stackoverflow.com/questions/29860272
更新时间:2024-03-11 11:03

最满意答案

正如你刚才提到的,es5-shim在浏览器的JavaScript引擎不兼容ES5的情况下增加了一些JavaScript函数,比如map,reduce,some和forEach。 Underscore.js在“_”命名空间中添加了类似于上述(和更多)的实用程序方法。 所以,在这种情况下,在同一个应用程序中使用这两个都是多余的。

也就是说,es5-shim增加了一些功能,比如Date.now,Date.toJSON,Function.bind,String.trim(以及更多),它们在Underscore.js中没有直接的等价物。 例如Underscore提供的_.bind和_.bindAll等同于Function.bind,但Underscore.js不提供Date.now和Date.toJSON。

因此,如果您使用es5-shim提供的其他方法,则可以在应用程序中使用es5-shim和Underscore.js。 但是,如果您不使用这些额外的方法,那么使用es5-shim只会是应用程序大小的不必要的增加和带宽的浪费。


es5-shim, as you rightly mentioned, adds some JavaScript functions like map, reduce, some and forEach on Array if the browser's JavaScript engine is not ES5 compatible. Underscore.js adds utility methods similar to the above (and more) within the "_" namespace. So, in this case, using both in the same application is redundant.

That said, es5-shim, adds a few more functions like Date.now, Date.toJSON, Function.bind, String.trim (and more) some which don't have direct equivalents in Underscore.js. For example Underscore does provide _.bind and _.bindAll that is equivalent to Function.bind, but Underscore.js does not provide Date.now and Date.toJSON.

So, if you use these additional methods provided by es5-shim you can stay with both es5-shim and Underscore.js in your application. But, if you are not using these additional methods, then using es5-shim would just be an unnecessary increase in application size and waste of bandwidth.

相关问答

更多
  • 发生这种情况是因为范围在循环内部发生了变化,您可以通过使用绑定功能将您的函数与this绑定来保持相同的范围。 bind()方法创建一个新的函数,该函数在调用时将其关键字设置为提供的值,并在调用新函数时提供的任何前面给定的参数序列。 代码示例: _.each(this.selectedCharges, function(selectedCharge, key){ if(selectedCharge._id == charge._id){ this.selectedCharges.spl ...
  • _.map(_.groupBy(arr, 'menu'), function(roles, menu) { var entry = {menu: menu}; _.each(roles, function(role) { entry[role.role] = "OK"; }); return entry; }) 我假设你的输出是: [ { "menu": "Setting", "admin": "OK", "user": "OK", "developer": "OK" }, { " ...
  • 您的代码存在多个问题: 除非你使用古老版本的jQuery,否则jQuery不需要shim 。 下划线也是如此。 你必须在所有小写字母中引用jQuery作为模块: jquery 。 它仍然在全局空间中导出jQuery ,但模块名称(放在传递给require或define依赖列表中)必须全部小写。 您不能在shim复制条目。 你有这个例子: angularRoute: { exports: "ngRoute" }, angularRoute: { deps: ['angular'] }, 只有第二 ...
  • 我们试试这个: $(".info:contains('...')").hide(); 请让我知道结果。 谢谢。 Let's try this: $(".info:contains('...')").hide(); Please let me know the result. Thanks.
  • Underscore的模板(故意)简单且极小,因此没有任何内置的格式化实用程序。 但是,您可以在<%= ... %>放置您想要的任何JavaScript表达式,以便您可以轻松添加自己的格式设置实用程序。 您可以在JavaScript中执行以下操作: window.fmt = { iso_date: function(d) { // Your favorite ISO 8601 date formatter goes here, this // is just a qu ...
  • 你会想要使用JavaScript版本。 CoffeeScript版本可能只是作者在使用CoffeeScript进行的,因为他是CoffeeScript和Underscore的作者。 另外,CoffeeScript版本引入了一个编译步骤(假设您在浏览器中使用它,而不是在具有node.js的服务器上)。 作为另一种选择,检查Lodash。 它是Underscore的下架替代品,并且由于许多原因是更好的选择。 它在过去几天刚刚发布了v1.0。 You'll want to use the JavaScript v ...
  • 你在这里检查了下划线测试套件吗? Have you checked Underscore Test suite here.
  • 正如你刚才提到的,es5-shim在浏览器的JavaScript引擎不兼容ES5的情况下增加了一些JavaScript函数,比如map,reduce,some和forEach。 Underscore.js在“_”命名空间中添加了类似于上述(和更多)的实用程序方法。 所以,在这种情况下,在同一个应用程序中使用这两个都是多余的。 也就是说,es5-shim增加了一些功能,比如Date.now,Date.toJSON,Function.bind,String.trim(以及更多),它们在Underscore.js ...
  • 定义了一个全局exports对象,它阻止了underscore.js的正确安装。 该对象声明了两个函数: compile()和compileToString() 。 函数的实现揭示了LF对象,它最有可能属于Disqus Javascript API: http : //www.livefyre.com/docs/javascript-sdk-reference 。 这是对不成功的underscore.js安装的调查。 仍然困惑于我现在该怎么做以及如何正确解决它: underscore.js,名为“expor ...
  • 谷歌Chrome Frame是一个应用程序,需要用户安装它,es5-shim是JavaScript代码,你只需要包含它。 如果你想在IE中使用AngularJS,你应该阅读: http : //docs.angularjs.org/guide/ie 。 简而言之,包括es5-shim(可选但非常有用)和JSON polyfill。 Google Chrome Frame is a application, and need user to install it, es5-shim is JavaScript ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。