次のコードでは、どのようthebody
にしてapp.body
両方をJQueryオブジェクトにすることができますが、.css
プロパティをに設定しても機能しますthebody
が、機能しませんapp.body
か?
var app = app || {};
app.show = function(html) {
this.baseElement.html(html);
};
app.body = $('body');
app.init = function() {
this.baseElement = $('div#app');
var thebody = $('body');
console.log(app.objectIsJquery(thebody)); //true
console.log(app.objectIsJquery(app.body)); //true
app.body.css('background-color', 'yellow'); //does not set the background color, no errors
//thebody.css('background-color', 'yellow'); //sets color correctly
};
app.start = function() {
this.baseElement.css('color', 'brown');
this.show(dp.qstr.addStar('testing'));
};
app.objectIsJquery = function(obj) {
return obj.selector != undefined;
}