嘿家伙我很新的JS和我只是经历了modal.js的语法,基本上我有一个小难度,很多经典的js插件使用下面的骨架该插件代码:访问插件原型函数使用数组square [] brakets
var Modal = function(element , options){
this.options = options
this.$body = $(document.body)
this.$element = $(element)
this.isShown = null
this.$backdrop =
this.scrollbarWidth = 0
}
Modal.prototype.toggle = function (_relatedTarget) {
// do something
}
Modal.prototype.show = function (_relatedTarget) {
// do something
}
var data = new Modal(somthing , radnom);
// now if we assume that option is "show" ,
//the show function in Modal will be executed
// but my question is data is not an array , so how can we use
// [] square brackets to access the properties of Modal/data ??
data[option](_relatedtarget);
现在我的问题是关于访问插件的属性,看看功能正在使用以下语法叫:
data[option](_relatedtarget);
看到我的代码中的注释。我们如何使用[]访问数据的属性,它不是一个数组吗?
谢谢。
Alex-Z。
'[]'是一个属性存取操作符,就像'.'。 – Xufox