首页 \ 问答 \ 什么是constructor.prototype引用?(What is constructor.prototype refering to?)

什么是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
更新时间:2023-02-26 18:02

最满意答案

第一个问题是为什么不使用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 the body..

相关问答

更多
  • 这是一个稍微不同的方法。 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 ...
  • 当分配一个事件处理函数时,直接分配函数引用,而不是函数的结果 ,所以放弃() (立即调用函数...重新加载页面),如下所示: $('#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 ...
  • 这应该工作: 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); } 你的循环的问题是悬停函数 ...
  • // 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 ...
  • 如果您想要将目标放在当前悬停的元素中,那么您可以在上下文中使用.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 ...
  • 您可以对表进行传递以创建单元格值和元素引用的映射: 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#on的调用转换为jQuery#one ,这将确保您的处理程序“每个事件类型每个元素最多执行一次”。 $(document).ready(function() { $(".end").appear(); $(".end").one("appear", function handler() { console.log('triggered'); }); }); ...
  • 相关文章

    更多
  • java prototype 模式
  • 基于prototype.js验证框架(validation.js)的三个应用
  • 从 prototype.js 深入学习 javascript 的面向对象特性
  • 一段代码的疑问
  • 请教怎样根据对象的引用得到包含它的对象的引用呢?
  • js怎么在引号里面引用变量
  • 微信API 引用
  • Tomcat 找不到引用项目类的问题
  • jsp中使用JavaBean出现“引用类不可用”
  • 各们帮忙看一下,为什么spring引用不到jdbcTemplate?
  • 最新问答

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