什么是constructor.prototype引用?(What is constructor.prototype refering to?)
在typescript中阅读Decorators的文档(我在这个片段上讨论了:
function sealed(constructor: Function) { Object.seal(constructor); Object.seal(constructor.prototype); }
当执行@sealed时,它将密封构造函数及其原型。
constructor.prototype
指向什么? 这种典型的继承有时会让人感到困惑。Reading the documentation for Decorators in typescript (I stumpled upon this snippet:
function sealed(constructor: Function) { Object.seal(constructor); Object.seal(constructor.prototype); }
When @sealed is executed, it will seal both the constructor and its prototype.
What does
constructor.prototype
point to? This prototypical inheritance can be a tad confusing at times.
原文:https://stackoverflow.com/questions/44477980
最满意答案
第一个问题是为什么不使用
for
循环 ?如果你仍然需要这样,你可以使用
$(function(){ var lgt= 5; $.each(new Array(lgt),function(i){ $('body').append('<li>'+i+'</li>') }); });
但正如其他人提到的那样,你无法直接将
li
元素添加到body
。The first question is Why not use a
for
loop ?If you still need to go this way you can use
$(function(){ var lgt= 5; $.each(new Array(lgt),function(i){ $('body').append('<li>'+i+'</li>') }); });
but as others have mentioned you cannot add
li
elements directly to thebody
..
相关问答
更多-
这是一个稍微不同的方法。 jsFiddle演示 var $headings = $('.ads'), $length = $headings.length, i = 0; setInterval(function() { $headings.css('color','black'); $headings.eq(i).css('color', 'red'); i = (i + 1) % $length; }, 3000); Here's a slightly di ...
-
您的测试太重,无法真正确定三个循环选项之间的实际差异。 如果你想测试循环,那么你需要尽可能多地从测试中删除非相关的工作。 您的测试包括: DOM选择 DOM遍历 元素突变 与循环本身相比,所有这些都是相当昂贵的操作。 当删除额外的东西时,循环之间的差异更加明显。 http://jsperf.com/asdasda223/4 在Firefox和Chrome中, for循环比其他循环快了超过100倍。 Your test is too heavy to really determine the actual d ...
-
jQuery中的无限循环(Infinite loop in jQuery)[2022-06-10]
当分配一个事件处理函数时,直接分配函数引用,而不是函数的结果 ,所以放弃() (立即调用函数...重新加载页面),如下所示: $('#daysLeftSort').change(changeURL); When assigning an event handler, assign the function reference directly, not the result of the function, so leave off the () (which calls the function imm ... -
如何在jQuery中循环(How to loop in jQuery)[2022-11-07]
这应该工作: for (i = 1; i <= 3; ++i) { (function(index){ $("#item-" + index).hover(function(){ $(".item-" + index).animate({opacity:1},"slow"); },function(){ $(".item-" + index).animate({opacity:0},"slow"); }); })(i); } 你的循环的问题是悬停函数 ... -
jQuery循环(jQuery loop)[2022-10-15]
// get an array of the divs (will act like one anyway) var divs = $('div.CCC'); // do something for each div divs.each(function() { // this refers to the current div as we loop through doSomethingWith(this); }); // or call your method on the ... -
jQuery“for”循环(jQuery “for” loop)[2023-06-03]
如果您想要将目标放在当前悬停的元素中,那么您可以在上下文中使用.find() / .children() (在事件处理程序中, this指的是处理程序所针对的元素 - 在本例中li元素)喜欢 //dom ready handler jQuery(function ($) { $('#menu > ul:first-child > li').hover(function () { //I think you want to target the child elements of th ... -
第一个问题是为什么不使用for循环 ? 如果你仍然需要这样,你可以使用 $(function(){ var lgt= 5; $.each(new Array(lgt),function(i){ $('body').append('
- '+i+'
') }); }); 但正如其他人提到的那样,你无法直接将li元素添加到body 。 The first question is Why not use a for loop ? If you still ne ... -
优化JQuery中的每个循环(Optimizing each loop in JQuery)[2024-01-20]
您可以对表进行传递以创建单元格值和元素引用的映射: var map = {}; $("tableName td").each(function() { map[$(this).text()] = this; }); 然后你的ajax回调可以这样做: $.each(data.groupIDs, function (index, val) { $(map[val]).find(".classA").removeClass("classB").addClass("classC"); }); (如果 ... -
我不知道咖啡脚本,但一般使用jQuery选择器不需要完整的路径。 例如$('tr > td > a > span.number')可以重写为$('.number') ,同样.each()通常用作.each(function(index, element) { YOUR CODE }); 。 看起来不合适的最后一件事是设置html,这通常是以.html('value') 。 所以在你的情况下$(element).html(i); 。 希望这可以帮助? I don't know coffee script bu ...
-
jQuery出现循环(jQuery appear loop)[2021-06-13]
将您对jQuery#on的调用转换为jQuery#one ,这将确保您的处理程序“每个事件类型每个元素最多执行一次”。 $(document).ready(function() { $(".end").appear(); $(".end").one("appear", function handler() { console.log('triggered'); }); }); ...