Answer the question
In order to leave comments, you need to log in
OOP in Javascript, inheritance: how to implement this?
How to implement similar in javascript if possible?
var put = function(elem, text) {
var text = encodeURIComponent(text);
return {
now: function(a) {
var a = encodeURIComponent(a) || '';
add: function() {
elem.outerHTML += text+a;
}
replace: function() {
elem.outerHTML = text+a;
}
}
after: function(time) {
// do smth
}
}
}
put(document.getElementById("div_id"), "Hello ").now("world!").replace;
Answer the question
In order to leave comments, you need to log in
You have almost everything right, only a couple of syntax errors and one logical one:
var put = function(elem, text) {
var text = encodeURIComponent(text);
return {
now: function(a) {
var a = encodeURIComponent(a) || '';
return {
add: function() {
elem.outerHTML += text + a;
},
replace: function() {
elem.outerHTML = text + a;
},
}
},
after: function(time) {
// do smth
},
}
}
put(document.getElementById("div_id"), "Hello ").now("world!").replace();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question