@littlepootis so you're saying if I create my class Foo, there is a construct that would allow my "toElement" function (or whatever it is called) to be invoked just by attempting to insert it? Like so: var blah = new Foo(); document.body.appendChild(blah);
?
Or would it have to be invoked using string serialization, vis-a-vis innerHTML?
The project I'm scrum master for is very laid back. So it's not required for me to be certified, but my project managers want to improve me so why not. Plus it's a huge resume booster in my area
Pretty much, let's say I have a class Foo. I want it so when I try to insert the class somewhere, it recognizes it and does exactly what @rlemon just said.
class Foo {
constructor() {
this.a = 'b';
}
}
document.body.innerHTML += new Foo().toString() // you want this to insert
/*
class Foo {
constructor() {
this.a = 'b';
}
}
*/
// as a string?
@Vap0r Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
Say if I have a bunch of those printed out on the page, I want a good way to maintain the state of each of those element sets.
@Luggage it wouldn't be obscuring if it was a practice that I was just ignorant to, but you're right, I don't want to add it if it's not done by anyone else lol
I have an application that has "weird" behavior, which I tracked down to a commit that added a library that adds a field to global. When I change that library to not change global, the weird behavior goes away
so.. two main directions. A funciton that generates a blob of html as a string (mustache, most template libraries), or a function that generates an object graph of html (like react, hyperscript, jsdom)
in both cases, the relationship comes from you attaching event handlers.
like.. this button click event calls myClass.doDomething()
@littlepootis Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
Anyways, I have an application that is on display in one of our lobbies. It uses AJAX to check the meeting schedule for our meeting rooms and displays them. This application runs 24/7.
Sometimes when our services go out or network latency is particularly bad the AJAX/setTimeout loop fails, and I come in in the morning to an application that has to be rebooted.
var xhr = new XMLHttpRequest();
xhr.open("POST", app_API);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader("Accept", "application/json;");
var self = this;
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 201 || xhr.status == 409) {
// Deal with error message from 409.
var data = JSON.parse(this.response);
I'd really like websockets, but I'm using the exchange web service to get my meetings for this application, and I can't think of a good trigger that wouldn't just involve hitting the web service constantly on the server and returning when there is a change.