Skip to content

Commit 4e7d61f

Browse files
author
zhangxinxu
committed
remove a string extend method
remove a string extend method
1 parent 408c1b5 commit 4e7d61f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/mobilebone.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
}, params = function(element) {
138138
if (!element || !element.getAttribute) return {};
139139

140-
var _params = {}, _dataparams = (element.getAttribute("data-params") || '').queryToObject();
140+
var _params = {}, _dataparams = _queryToObject(element.getAttribute("data-params") || '');
141141

142142
// rules as follow:
143143
// data-* > data-params > options > defaults
@@ -474,7 +474,7 @@
474474
// if 'trigger_or_options' is a element, we should turn it to options-object
475475
var params_from_trigger = {}, attr_mask;
476476
if (trigger_or_options.nodeType == 1) {
477-
params_from_trigger = (trigger_or_options.getAttribute("data-params") || "").queryToObject();
477+
params_from_trigger = _queryToObject(trigger_or_options.getAttribute("data-params") || "");
478478
// get params
479479
for (key in defaults) {
480480
// data-* > data-params > defaults
@@ -777,16 +777,18 @@
777777
return element;
778778
};
779779
/**
780-
* prototype extend method: convert query string to key-value object
780+
* privite method: convert query string to key-value object
781781
**/
782-
String.prototype.queryToObject = function() {
782+
var _queryToObject = function(string) {
783783
var obj = {};
784-
this.split("&").forEach(function(part) {
785-
var arr_part = part.split("=");
786-
if (arr_part.length > 1) {
787-
obj[arr_part[0]] = part.replace(arr_part[0] + "=", "");
788-
}
789-
});
784+
if (typeof string == "string") {
785+
string.split("&").forEach(function(part) {
786+
var arr_part = part.split("=");
787+
if (arr_part.length > 1) {
788+
obj[arr_part[0]] = part.replace(arr_part[0] + "=", "");
789+
}
790+
});
791+
}
790792
return obj;
791793
};
792794

0 commit comments

Comments
 (0)