产生这个需求的场景见下面的代码:
var param = {}; param.imgSrc = capture; $.ajax({ data: param, success: function (data) { } });
Javascript能不能像C#创建匿名对象那样实现,类似效果如下:
$.ajax({ data: new { imgSrc: capture },//仅是效果示例,实际运行会报错 success: function (data) { } });
var empty={}; var point={x:0,y:0}; var point2={x:point,y:point.y+1}; var book={ "main title":"JavaScript", 'sub-title':"The Definitive Guide", "for":"all audiences", author:{ firstname:"David" , surname:"Flanagan" }}
上面代码摘录自《JavaScript权威指南》
例子中去掉new就可以了;
另外可以使用Object.Create({x:0});
var param =
{
key = value,
key1 = value1
};
前面写错了,这样写是对的
$.ajax({
data: { Name: "Rich", Age: "男" },
success: function (data) {
alert(1);
}
});
var ob={createNew:function(){var ob;ob.id=1;return ob;}};
var ob1=ob.createNew();