我拿起了一些代码,我才刚刚理解了new Function();.通过jslint,new Function();突出显示为意外.我开始尝试做以下事情.
var func = new Function();
func.property = "some property";
return func;
Run Code Online (Sandbox Code Playgroud)
一个替代品.
var func = new function(){
this.property = "some property";
}
return func;
Run Code Online (Sandbox Code Playgroud)
工作和第二个工作都被js-lint忽略了.
我在这里做了什么壮观的事情,还是这个完全一样?这样使用语法是否正确new Function();?
附上原始代码摘录.
 var $ = (function() {
   function doCSS(prop, val) {
     var isSet = Boolean(val),
       action = CSSStyleDeclaration.prototype.setProperty,
       args = arguments;
     if (isSet) {
       this.each(function(node, i) {
         action.apply(node.style, args);
       });
       return this;
     } else if (typeof(prop) === 'object') {
       this.each(function(node, i) {
         Object.keys(prop).forEach(function(property) {
           node.style[property] …Run Code Online (Sandbox Code Playgroud)我想知道是否有人可以解释为什么在第一个创建的div中背景颜色不起作用,它在第二个例子中也是如此.
$("<div/>", {
width:300,
height:400,
backgroundColor:"#425412", //background-color does not work
text: "hello there"
}).appendTo("body");
Run Code Online (Sandbox Code Playgroud)
注意:如果没有background-color属性,将创建div.
// works as defined including background-color
$("<div style='width:300; height:400; background-color:#425412;'>hello there</div>").appendTo("body");
Run Code Online (Sandbox Code Playgroud)
第一种方法有限制吗?