私はjavascriptライブラリに取り組んでいます。コードは次のとおりです。
(function (window) {
var regex = {
Id : /^[#]\w+$/,
Class : /^[.]\w+$/,
Tag : /^\w+$/,
validSelector : /^([#]\w+|[.]\w+|\w+)$/
},
tex = function(selector){
//only some of the functions need to select an element
//EX:
// style: tex(selector).style(style);
//one that would not need a selector is the random number function:
// tex().random(from,to);
if (selector){
if (typeof selector === 'string'){
var valid = validSelector.test(selector);
if( valid ){
if(regex.Id.test(string)){
this = document.getElementById(selector);
}
if(regex.Class.test(string)){
this = document.getElementByClass(selector);
}
if(regex.Tag.test(string)){
this = document.getElementByTagName(selector);
}
}
}else if(typeof selector === 'object'){
this = selector;
}
//this = document.querySelector(selector);
// I could make a selector engine byt I only need basic css selectors.
}
},
tex.prototype = {
dit : function(){
this.innerHTML = 'Hi?!?!?!'
}
};
window.tex = tex;
})(window);
Web ページでライブラリを使用しようとするまでは、すべてが適切なコードのように見えます。tex.prototype
アクティブ化しようとすると、次の行を参照して、「エラー: 予期しないトークン '.'」というエラーが表示されます。
},
tex.prototype = {
dit : function(){
私のコードの問題が何であるかを誰かが知っていますか?
どうもありがとう!