質問編集履歴
3
関数型→クラス型
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,59 +20,55 @@
|
|
20
20
|
id:""
|
21
21
|
}
|
22
22
|
//-----------------------------------------------------------------------------------------------------------------------------------
|
23
|
-
|
23
|
+
class set{//set関数
|
24
|
-
set.prototype = {//プロトタイプ
|
25
|
-
body
|
24
|
+
body(){
|
26
25
|
system["id"]="<<body>>";
|
27
26
|
return this;
|
28
|
-
}
|
27
|
+
}
|
29
|
-
title
|
28
|
+
title(text){
|
30
29
|
document.title=text;
|
31
30
|
return this;
|
32
|
-
}
|
31
|
+
}
|
33
|
-
icon
|
32
|
+
icon(url){
|
34
33
|
const new_ele = document.createElement("link");
|
35
34
|
new_ele.rel="icon";
|
36
35
|
new_ele.href=url;
|
37
36
|
document.head.appendChild(new_ele);
|
38
37
|
return this;
|
39
|
-
}
|
38
|
+
}
|
40
|
-
css
|
39
|
+
css(name,option){
|
41
40
|
let key_name = [];
|
42
41
|
let key_option = [];
|
43
42
|
if(system["id"]!==""){
|
44
43
|
let id = undefined;
|
45
|
-
if(system["id"]==="<<body>>")
|
44
|
+
if(system["id"]==="<<body>>")id = document.body;
|
46
|
-
id = document.body;
|
47
|
-
|
45
|
+
else
|
48
46
|
id = document.getElementById(system["id"]);
|
47
|
+
if((typeof name)==="object"){
|
48
|
+
key_name=[...(Object.keys(name))]
|
49
|
+
for(let i = 0;i<key_name.length;i++){
|
50
|
+
key_option.push(name[key_name[i]]);
|
49
|
-
}
|
51
|
+
}
|
50
|
-
|
52
|
+
}else{
|
51
|
-
key_name
|
53
|
+
key_name.push(name);
|
54
|
+
key_option.push(option);
|
55
|
+
}
|
52
56
|
for(let i = 0;i<key_name.length;i++){
|
53
|
-
key_
|
57
|
+
css_edit(key_name[i],id,key_option[i]);
|
54
58
|
}
|
55
|
-
}else{
|
56
|
-
key_name.push(name);
|
57
|
-
key_option.push(option);
|
58
|
-
}
|
59
|
-
for(let i = 0;i<key_name.length;i++){
|
60
|
-
css_edit(key_name[i],id,key_option[i]);
|
61
|
-
}
|
62
|
-
key_name=[];
|
59
|
+
key_name=[];
|
63
|
-
return this;
|
60
|
+
return this;
|
64
61
|
}else{
|
65
62
|
console.error("エラー:\nidが指定されていません");
|
66
63
|
}
|
67
|
-
}
|
64
|
+
}
|
68
|
-
change
|
65
|
+
change(text){
|
69
66
|
return $(text);
|
70
67
|
}
|
71
68
|
}
|
72
69
|
//-----------------------------------------------------------------------------------------------------------------------------------
|
73
|
-
|
70
|
+
class add{
|
74
|
-
add.prototype = {//プロトタイプ
|
75
|
-
canvas
|
71
|
+
canvas(sizex,sizey,id,color){
|
76
72
|
const new_ele = document.createElement("canvas");
|
77
73
|
new_ele.style.backgroundColor=color;
|
78
74
|
new_ele.width=sizex;
|
@@ -81,62 +77,61 @@
|
|
81
77
|
system["id"]=id;
|
82
78
|
document.body.appendChild(new_ele);
|
83
79
|
return this;
|
84
|
-
}
|
80
|
+
}
|
85
|
-
p
|
81
|
+
p(text,id){
|
86
82
|
const new_ele = document.createElement("p");
|
87
83
|
new_ele.id=id;
|
88
84
|
new_ele.appendChild(document.createTextNode(text));
|
89
85
|
document.body.appendChild(new_ele);
|
90
|
-
}
|
86
|
+
}
|
91
|
-
h1
|
87
|
+
h1(text,id){
|
92
88
|
const new_ele = document.createElement("h1");
|
93
89
|
new_ele.id=id;
|
94
90
|
new_ele.appendChild(document.createTextNode(text));
|
95
|
-
document.body.appendChild(new_ele);
|
91
|
+
document.body.appendChild(new_ele);
|
96
|
-
}
|
92
|
+
}
|
97
|
-
h2
|
93
|
+
h2(text,id){
|
98
94
|
const new_ele = document.createElement("h2");
|
99
95
|
new_ele.id=id;
|
100
96
|
new_ele.appendChild(document.createTextNode(text));
|
101
|
-
document.body.appendChild(new_ele);
|
97
|
+
document.body.appendChild(new_ele);
|
102
|
-
}
|
98
|
+
}
|
103
|
-
h3
|
99
|
+
h3(text,id){
|
104
100
|
const new_ele = document.createElement("h3");
|
105
101
|
new_ele.id=id;
|
106
102
|
new_ele.appendChild(document.createTextNode(text));
|
107
|
-
document.body.appendChild(new_ele);
|
103
|
+
document.body.appendChild(new_ele);
|
108
|
-
}
|
104
|
+
}
|
109
|
-
h4
|
105
|
+
h4(text,id){
|
110
106
|
const new_ele = document.createElement("h4");
|
111
107
|
new_ele.id=id;
|
112
108
|
new_ele.appendChild(document.createTextNode(text));
|
113
|
-
document.body.appendChild(new_ele);
|
109
|
+
document.body.appendChild(new_ele);
|
114
|
-
}
|
110
|
+
}
|
115
|
-
h5
|
111
|
+
h5(text,id){
|
116
112
|
const new_ele = document.createElement("h5");
|
117
113
|
new_ele.id=id;
|
118
114
|
new_ele.appendChild(document.createTextNode(text));
|
119
|
-
document.body.appendChild(new_ele);
|
115
|
+
document.body.appendChild(new_ele);
|
120
|
-
}
|
116
|
+
}
|
121
|
-
h6
|
117
|
+
h6(text,id){
|
122
118
|
const new_ele = document.createElement("h6");
|
123
119
|
new_ele.id=id;
|
124
120
|
new_ele.appendChild(document.createTextNode(text));
|
125
|
-
document.body.appendChild(new_ele);
|
121
|
+
document.body.appendChild(new_ele);
|
126
|
-
}
|
122
|
+
}
|
127
|
-
change
|
123
|
+
change(text){
|
128
124
|
return $(text);
|
129
125
|
}
|
130
126
|
}
|
131
127
|
//-----------------------------------------------------------------------------------------------------------------------------------
|
132
|
-
|
128
|
+
class remove{//remove関数
|
133
|
-
remove.prototype = {//プロトタイプ
|
134
|
-
id
|
129
|
+
id(id){
|
135
130
|
let element = document.getElementById(id);
|
136
131
|
element.remove();
|
137
132
|
return this;
|
138
|
-
}
|
133
|
+
}
|
139
|
-
change
|
134
|
+
change(){
|
140
135
|
return $(text);
|
141
136
|
}
|
142
137
|
}
|
2
エラー文の提示
test
CHANGED
File without changes
|
test
CHANGED
@@ -185,3 +185,5 @@
|
|
185
185
|
});
|
186
186
|
});
|
187
187
|
```
|
188
|
+
エラー文はこれです:
|
189
|
+
Uncaught TypeError: Cannot read properties of undefined (reading 'change')
|
1
書式の改善
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
javascriptのlibraryをつくっているときのエラー
|
1
|
+
javascriptのlibraryをつくっているときのエラー
|
test
CHANGED
@@ -166,8 +166,7 @@
|
|
166
166
|
"margin":"0",
|
167
167
|
"padding":"0"
|
168
168
|
});
|
169
|
-
$("%add").h1("タイトル","h1")
|
169
|
+
$("%add").h1("タイトル","h1").change("%set").css({
|
170
|
-
$("%set").css({
|
171
170
|
"color":"#000000",
|
172
171
|
"text-align":"center",
|
173
172
|
"font-size":"20"
|