如何使用ES6克隆Javascript类实例.
我对基于jquery或$ extend的解决方案不感兴趣.
我已经看到对对象克隆的相当古老的讨论表明这个问题非常复杂,但是使用ES6可以得到一个非常简单的解决方案 - 我会把它放在下面,看看人们是否认为它是令人满意的.
编辑:建议我的问题是重复的; 我看到了这个答案,但它已经有7年的历史,并且使用前ES6 js涉及非常复杂的答案.我建议我的问题,允许ES6,有一个非常简单的解决方案.
这是我的代码:
request_xml: function()
{
http_request = false;
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
}
if (!http_request)
{
return false;
}
http_request.onreadystatechange = this.response_xml;
http_request.open('GET', realXmlUrl, true);
http_request.send(null);
xmlDoc = http_request.responseXML;
},
response_xml:function ()
{
if (http_request.readyState == 4)
{
if(http_request.status == 404 && countXmlUrl<=3)
{
countXmlUrl++;
realXmlUrl = xmlUrl[countXmlUrl];
this.request_xml();
}
if (http_request.status == 200)
{
xmlDoc = http_request.responseXML;
alert("need to update3");
this.peter_save_data();
}
}
},
peter_save_data:function()
{
// removed function code
},
Run Code Online (Sandbox Code Playgroud)
奇怪的是,警报没有问题,但是下面的函数调用给了我这个错误:
Error: this.peter_save_data is not …Run Code Online (Sandbox Code Playgroud) 我想在ajax函数完成时显示通知.我的ajax很好我似乎无法让通知工作.我有jquery和一切安装,我也有notify.js.在Chrome控制台中,我发现了以下错误
未捕获的TypeError:$ .notify不是函数
而且我的ajax响应很好.以下是通知代码,
@if (TempData.ContainsKey("SuccessMessage"))
{
<script>
$.notify({
message: '@TempData["SuccessMessage"].ToString()'
}, {
type: 'success',
delay: 7000,
});
</script>
}
Run Code Online (Sandbox Code Playgroud)
以下是为此添加的参考,
<script src="/bootstrap/js/notify.js"></script>
<script src="/scripts/js/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
如果我犯了任何错误,请告诉我
我正在尝试使用d3.js绘制折线图.
function lineChart(){
...
}
function update(){
...
var lineChart = lineChart()
.x(d3.scale.linear().domain([2011, 2014]))
.y(d3.scale.linear().domain([0, 1000000]));
...
}
Run Code Online (Sandbox Code Playgroud)
但控制台说Uncaught TypeError: lineChart is not a function.
如何解决这个问题?
我有以下功能:
$(function(){
performance();
function performance(){
pHandler = setTimeout(performance,3000)
perOb = [];
alert('hhhh')
$(".performance").each(function(i){
perOb[i] = $(this);
url = '/cavity/performance/'+perOb[i].attr('data-id')+'/'+jobId;
//perOb[i].html('%');
$.ajax({
type: "GET",
//dataType: "json",
url: url,
success: function(data){
perOb[i].html(data.performance+"%");
},
error: function(xhr, status, response){
console.log(xhr.responseText);
},
});
});
}
});
Run Code Online (Sandbox Code Playgroud)
我试图从另一个事件中调用它,如下所示:
$('#in-between').change(function(){
if ($(this).prop('checked')){
window.clearTimeout(pHandler);
alert('yesr')
}
else{
alert('noo')
performance();
}
})
Run Code Online (Sandbox Code Playgroud)
我有错误performance is not a function.我试过了$.performance(),jQuery.performance()我也尝试将它分配给变量,如:
perf = $(function(){
performance();
function performance(){
pHandler = setTimeout(performance,3000)
.......
Run Code Online (Sandbox Code Playgroud)
并将其称为perf.performance() 但所有尝试的人都没有成功地从事件中调用它.
此问题与JavaScript错误不同 …
javascript ×5
jquery ×3
ajax ×1
asp.net-mvc ×1
d3.js ×1
ecmascript-6 ×1
es6-class ×1
node.js ×1
notify ×1