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
最满意答案
创建DOM元素非常昂贵。 尽可能地尝试并避免它。 话虽如此,新发布的jQuery 1.4显然提高了性能,但如果可以的话,仍然可以避免它。
来自jQuery 1.4发布 :
jQuery(“<div>”)
jQuery(“<div/>”)
和jQuery(“<div></div>”)
( jQuery()Documentation , Commit )现在所有三个使用相同的代码路径(使用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/>”)
andjQuery(“<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.
相关问答
更多-
在Unity中优化动画以在移动设备上显示数十甚至数百个动画(Optimizing animations to show dozens or even hundreds on mobile in Unity)[2023-05-05]
荣誉@ @ Blindman67为我提供了一般情况。 在他的帮助下,我能够创建这个脚本: using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; public class AnimationConverter : MonoBehaviour { //For example: Assets/_@MYSTUFF/StaticAnimations/ public stri ... -
创建DOM元素非常昂贵。 尽可能地尝试并避免它。 话虽如此,新发布的jQuery 1.4显然提高了性能,但如果可以的话,仍然可以避免它。 来自jQuery 1.4发布 : jQuery(“”) jQuery(“”)和jQuery(“”) ( jQuery()Documentation , Commit ) 现在所有三个使用相同的代码路径(使用document.createElement),提高jQuery("")性能jQuery("...我当时仍然是JS n00b,然后我的代码变得过于膨胀。 一些简单的整合和重新制定确实有所帮助。 但是,现在还有这个JS插件来帮助平滑JS动画: Velocity.js .....对于那些可能在未来降落的人来说,这里有更好的东西: GSAP I was and still am a JS n00b, and my code then was way over-bloated. Some simple consolidation and reformulation really did help. Howeve ...我设法增加了对事件的反击。 这是我的代码版本: angular.module('myApp', []) .directive('console', ['$rootScope', function($rootScope) { return { restrict: 'E', template: [ '', '
用jQuery创建新的div?(Creating new divs with jQuery?)[2023-12-13]
用这个 : function addSlot(){ maxChecks = maxChecks+1; var count = jQuery('.member').length; var div_id = count + 1; $("#list").append(""); } 获取具有类'member'的div的总数,然后在DIV id中执行+1。 Use this : func ...JQuery性能:删除类(JQuery Performance: removing class)[2023-08-25]
第二种方式( .find('.modified') )在所有主要桌面浏览器(Opera,IE,Edge,Chrome,Firefox,Chromium,没有测试移动浏览器)方面表现更好,性能更好。 谷歌Chrome 61 :22K操作/秒vs 214K操作/秒。 Firefox 55 :26K op / s vs 342K op / s。 铬59 :21K op / s vs 184K op / s。 Opera 46.0 :22K op / s vs 198K op / s。 Edge 25.10586. ...用jquery删除div(Removing divs with jquery)[2023-06-23]
您可以使用.closest()将父母爬上您的class="row",如下所示: $(".removeRow").click(function() { $(this).closest("div.row").remove(); }); You can use .closest() to climb up the parents to your class="row", like this: $(".removeRow").click(function() { $(this). ...您可以使用filter()来查看文本是否在数组中,因此只能循环遍历元素一次,而不是像您一样循环多次 var remove = function remove(items){ $("div.l1 p").filter(function(){ return $.inArray( $(this).text(), items) !==-1; }).parent().parent().remove(); } ...一切安好。 您可能正在尝试在加载jQuery或DOM准备好之前执行该代码,但是一旦所有内容到位,您将使用.size()函数进行测试。 确保将它全部包装在文档就绪功能中,你应该很好。 Everything is fine. You are probably trying to execute that code before jQuery is loaded or the DOM is ready, but then you are testing with the .size() function once ...所以我通过一些事情来改善这个问题。 首先,减少角元件的数量大大提高了性能。 其次,我使用jquery-animate-enhanced进行动画制作,这也大大改善了翻译! 第三,我使用animate.css作为我的淡入淡出动画,这很棒。 我仍然试图通过iOS或Android中的视图回收来提高性能,但我发现ng-repeat对此并不满意。 所以,我可能不得不实现指令。 谢谢! So I improved the problem thanks to a few things. First, reducing th ...相关文章
更多- javascript 问题
- javascript的验证
- 请教javascript问题
- javascript 注释
- javascript 基本语法
- JavaScript 事件
- JavaScript 事件
- javascript url编码
- javascript常用对象
- 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的基本操作命令。。。