0
我想用coffeescript在js類中包裝一些pliugin選項。返回一個具有咖啡類的
在平原JS我有
toastr.options = {
"closeButton" : false,
"debug" : false,
"positionClass" : "toast-bottom-right",
"onclick" : null,
"showDuration" : "300",
"hideDuration" : "1000",
"timeOut" : "8000",
"extendedTimeOut" : "1000",
"showEasing" : "swing",
"hideEasing" : "linear",
"showMethod" : "fadeIn",
"hideMethod" : "fadeOut"
}
隨着CoffeeScript的
class @ToastrOptions
constructor: ->
'closeButton': false
'debug': false
'positionClass': 'toast-bottom-full-width'
'onclick': null
'showDuration': '300'
'hideDuration': '1000'
'timeOut': '8000'
'extendedTimeOut': '1000'
'showEasing': 'swing'
'hideEasing': 'linear'
'showMethod': 'fadeIn'
'hideMethod': 'fadeOut'
toastr.options = new ToastrOptions
當我檢查toastr.options
的已經是空的{}。爲什麼?
你的JS是沒有階級,它是一個對象字面,那你爲什麼使用與CoffeeScript的'class' ??? – Bergi