草庐IT

copy-constructor

全部标签

javascript - 为什么 MDN 的 `Object.create` polyfill 没有设置 `prototype.constructor` ?

考虑MDN'sObject.createpolyfill:if(typeofObject.create!='function'){(function(){varF=function(){};Object.create=function(o){if(arguments.length>1){throwError('Secondargumentnotsupported');}if(o===null){throwError('Cannotsetanull[[Prototype]]');}if(typeofo!='object'){throwTypeError('Argumentmustbean

javascript - 在移动设备中使用 document.execCommand ('copy' )

有没有办法复制到手机剪贴板?我已经研究了几天,但没有找到好的解决方案。Clipboard.js似乎无法在移动设备上运行,给我一个错误“不支持:(”我目前正在使用以下功能:functioncopytext(text){vartextField=document.createElement('textarea');textField.innerText=text;document.body.appendChild(textField);textField.select();document.execCommand('copy');textField.remove();}在我的桌面上的chr

javascript - 云函数 : How to copy Firestore Collection to a new document?

我想在发生事件时使用CloudFunctions在Firestore中制作一个集合的副本我已经有了迭代集合并复制每个文档的代码constfirestore=admin.firestore()firestore.collection("products").get().then(query=>{query.forEach(function(doc){varpromise=firestore.collection(uid).doc(doc.data().barcode).set(doc.data());});});有更短的版本吗?一次复制整个集合? 最佳答案

javascript - 我可以使用 constructor.name 来检测 JavaScript 中的类型吗

我可以使用“constructor”属性来检测JavaScript中的类型吗?或者有什么我应该知道的。例如:vara={};a.构造函数名称;//输出“对象”或varb=1;b.构造函数名称;//输出“数字”或vard=newDate();d.构造函数名称;//输出“日期”而不是对象或varf=newFunction();f.构造函数名称;//输出“函数”而不是对象只有在参数上使用它时arguments.constructor.name;//像第一个例子一样输出对象我经常看到开发人员使用:Object.prototype.toString.call([])或Object.prototy

javascript - 为什么要将 Something 分配给 Something.prototype.constructor?

我正在阅读有关Javascript原型(prototype)属性如何与继承一起工作的内容,然后开始查看Angular.js代码并提出了一些问题。首先,我读到原型(prototype)属性指向一个对象,该对象具有一个“构造函数”属性,该属性指向用于创建该对象的原始函数。例如://ThisistheconstructorfunctionShape(){this.position=1;}//TheconstructorpointsbacktotheoriginalfunctionwedefinedShape.protoype.constructor==Shape;原型(prototype)还

javascript - 不要用 new Constructor 创建对象

是否可以选择不在构造函数中创建具有特定条件的对象,例如functionMonster(name,hp){if(hp 最佳答案 我认为你应该做的是抛出一个异常。functionMonster(name,hp){if(hp 关于javascript-不要用newConstructor创建对象,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/15355908/

javascript - 收到 "No parameterless constructor defined"错误,不确定原因

出于某种原因,我的一个特定AJAX调用出现“未定义无参数构造函数”错误。这是代码:CallAndReplace(JSON.stringify(model),url,$("#panel"));functionCallAndReplace(data,url,replace){$.ajax({url:url,type:"post",contentType:"application/json;charset=utf-8",data:data,success:function(result){replace.html(result);},error:function(x,e){if(x.stat

javascript - 在 Bootstrap 模式中调用时,工作 "Copy to Clipboard"函数不起作用

目标:将Bootstrap模式中的文本复制到剪贴板。JS:$(document).ready(function(){$(document).on('click','#copy-btn',function(){//varvalue=$('#error-message').html();//usingastaticvalue,justtoeliminateanyquestion//aboutwhatshouldbecopied.copytext('kilroytestedthis');})});functioncopytext(text){vartextField=document.cre

当我使用 document.execCommand ("copy"时,javascript 换行符不适用)

你好我正在使用下面的代码构建一个字符串并复制它,但是当我粘贴它时在输出中换行符不适用functioncopyToClipboardShipto(){var$temp=$("");$("body").append($temp);varstr1="@(Model.firstName)";varstr2="";varstr3="@(Model.lastName)";varstr4="\n";varstr5="@(Model.shiptoes[0].address.address1)";varstr6=",";varstr7="@(Model.shiptoes[0].address.addre

javascript - document.execCommand ('copy' ) 在 Chrome 上不工作

仅在Chrome上document.execCommand('copy')返回true但不复制文本,它清除剪贴板。我找不到遇到同样问题的人,有很多类似的问题,但请不要将其标记为重复,除非它确实是重复的。我在selection.addRange()之前调用selection.removeAllRanges()。selection.getRangeAt(0).cloneContents()返回包含正确文本的片段文本区域中的文本未显示为选中如果我在document.execCommand('copy')之前调用textarea.select(),文本将显示为选中状态并复制到剪贴板。我不想这样