在您说这是一个重复之前我已经阅读了所有其他帖子并且他们有点解决了我的问题但现在我需要知道为什么以下出现作为未捕获的SyntaxError:意外的令牌> 下面我包括我的整个图书馆,所以你可以看到我编码的希望这将有用,请帮助我
php2js.$this->();
这是我的图书馆
php2js = window.php2js || {};
php2js = function () {
var yourVar1;
var yourVar2;
publicFunc1 = function(content) {
document.write(content);
}
publicFunc2 = function(handle, first, last) {
var string = handle.split(first);
if (1 in string) {
var output = string[1].split(last);
return output[0];
}
return '';
}
publicFunc3 = function(str,begin,end) {
t = str.split(begin);
t = t[1].split(end);
return t[0];
}
publicFunc4 = function(delimiter, string, limit) {
if (arguments.length < 2 ||
typeof delimiter === 'undefined' ||
typeof string === 'undefined') {
return null
}
if (delimiter === '' ||
delimiter === false ||
delimiter === null) {
return false
}
if (typeof delimiter === 'function' ||
typeof delimiter === 'object' ||
typeof string === 'function' ||
typeof string === 'object') {
return {
0: ''
}
}
if (delimiter === true) {
delimiter = '1'
}
delimiter += ''
string += ''
var s = string.split(delimiter)
if (typeof limit === 'undefined') return s
if (limit === 0) limit = 1
if (limit > 0) {
if (limit >= s.length) {
return s
}
return s
.slice(0, limit - 1)
.concat([s.slice(limit - 1)
.join(delimiter)
])
}
if (-limit >= s.length) {
return []
}
s.splice(s.length + limit)
return s
};
publicFunc5 = function(text, name, type) {
var a = document.createElement("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
a.click();
}
publicFunc6 = function(id, string) {
var element = document.getElementById(id);
element.innerHTML = string;
}
publicFunc7 = function(grab) {
var parts = window.location.search.substr(1).split("&");
var $_GET = {};
for (var i = 0; i < parts.length; i++) {
var temp = parts[i].split("=");
$_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
}
return $_GET[grab];
}
publicFunc8 = function(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
publicFunc9 = function(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
publicFunc10 = function() {
return navigator.userAgent;
}
publicFunc11 = function(str) {
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
}
publicFunc12 = function() {
var obj = {}
obj.foo = 42;
var bar = 'foo';
console.log(obj[bar]);
}
return {
"echo" : publicFunc1,
"GetBetween" : publicFunc2,
"GBS" : publicFunc3,
"explode" : publicFunc4,
"fcd" : publicFunc5,
"echoById" : publicFunc6,
"$_GET" : publicFunc7,
"setCookie" : publicFunc8,
"$_COOKIE" : publicFunc9,
"$UA" : publicFunc10,
"htmlentities" : publicFunc11,
"$this->" : publicFunc12
}
}();
答案 0 :(得分:2)
因此,您有一个存储有一些方法的对象。键的值在点语法中无效。要使用您的代码调用它,您需要使用括号表示法。基本理念:
var php2js = (function() {
return {
"$this->": function() {
console.log("hey");
}
};
}());
php2js["$this->"]();