首页 \ 问答 \ JavaScript有类吗?(Does JavaScript have classes?)

JavaScript有类吗?(Does JavaScript have classes?)

一个朋友和我上周有个争论。 他表示没有像JavaScript这样的课程。

我说有可以说var object = new Object()

他说“因为没有使用字class这不是一个班。”

谁是对的


作为笔记; 对于将来,您需要一个简洁的Classy JS实现:

https://github.com/tnhu/jsface


编辑:2017年7月

ECMAScript 2015中引入的JavaScript类主要是基于JavaScript现有基于原型的继承的语法糖。 类语法不是向JavaScript引入新的面向对象的继承模型。 JavaScript类提供了一个更简单和更清晰的语法来创建对象并处理继承。

- Mozilla ES6课程: https : //developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes


A friend and I had an argument last week. He stated there were no such things as classes in JavaScript.

I said there was as you can say var object = new Object()

He says "as there is no word class used. It's not a class."

Who is right?


As a note; For future you needing a succinct Classy JS implement:

https://github.com/tnhu/jsface


Edit: July 2017

JavaScript classes introduced in ECMAScript 2015 are primarily syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax is not introducing a new object-oriented inheritance model to JavaScript. JavaScript classes provide a much simpler and clearer syntax to create objects and deal with inheritance.

- Mozilla ES6 Classes: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes


原文:https://stackoverflow.com/questions/2752868
更新时间:2023-05-09 20:05

最满意答案

创建DOM元素非常昂贵。 尽可能地尝试并避免它。 话虽如此,新发布的jQuery 1.4显然提高了性能,但如果可以的话,仍然可以避免它。

来自jQuery 1.4发布

jQuery(“<div>”) jQuery(“<div/>”)jQuery(“<div></div>”)jQuery()DocumentationCommit

现在所有三个使用相同的代码路径(使用document.createElement),提高jQuery("<div></div>")性能jQuery("<div></div>") 。 请注意,如果您指定属性,我们将使用浏览器的本地解析(使用innerHTML)。

是的,重用要好得多。


Creating DOM elements is expensive. Try and avoid it as much as possible. That being said, the newly released jQuery 1.4 apparently improves the performance but still avoid it if you can.

From jQuery 1.4 Released:

jQuery(“<div>”) jQuery(“<div/>”) and jQuery(“<div></div>”) (jQuery() Documentation, Commit)

All three now use the same code path (using document.createElement), improving performance for jQuery("<div></div>"). Note that if you specify attributes, we use the browser’s native parsing (using innerHTML).

Yes it's much better to reuse.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。