无法使用parseJSON
(function ($) { var Carousel = function (obj) { this.poster = obj; // 默认配置 this.setting = { width: 1000, height: 270, posterWidth: 640, posterHeight: 270, scale: 0.9, verticalAlign: "middle", speed: 500, }; console.log(this.getSetting()); }; Carousel.prototype = { // 获取人工配置参数 getSetting: function () { var setting = this.poster.attr("data-setting"); if (setting && setting != "") { return $.parseJSON(setting); }else{ return {}; }; } }; Carousel.init = function (posters) { var _this_ = this; posters.each(function () { new _this_($(this)); }); }; window["Carousel"] = Carousel;})(jQuery);
在getsetting方法中return this.setting是可以的,但只要改成return $.parseJSON(setting)就报错