【发布时间】:2018-11-07 18:26:59
【问题描述】:
我最近为 JavaScript 制作了一个自定义框架,但我的 '.css()' 函数不能用作对象表示法,这是我的代码的一部分:
const aps = function(selector) {
if (!(this instanceof aps)) {
return new aps(selector);
};
this.el = document.querySelectorAll(selector);
var about = {
Version: "0.3",
Author: "AppleProSchool, Adam Izgin",
Created: "Fall 2018, Tuesday 5, November",
Updated: "Tuesday 6, November",
}
};
aps.prototype.css = function(property, value) {
this.el.forEach(function(element) {
element.style[property] = value;
});
return this;
};
例如,如果我会这样做:
(window.onload = function() {
aps('.test').css({ background: '#0f0' });//That does not return anything. Why?
});
但是当我这样做时:
(window.onload = function() {
aps('.test').css('background', '#0f0');//It works.
});
我确实有一个红色背景的 div。
任何想法为什么?还是谢谢你。
【问题讨论】:
标签: javascript frameworks