Hey sometimes I have to admit, we’re really out of our minds. I was programming a publish function for an article and, I got this bug, it’s so funny I’ve decided to make a post out of it. Here’s the code :
PublishArticle: function(){
if(this.PublishButton.get("label") == "Publish"){
this.State = "Published";
this.SaveArticle();
this.PublishButton.set("label", "Unpublish");
}
if(this.PublishButton.get("label") == "Unpublish"){
this.State = "Draft";
this.SaveArticle();
this.PublishButton.set("label", "Publish");
}
},
Aint’ that crazy ?

Hey just a little something regarding this code and article
1) What’s the bug ?
2) maybe using an else would be cleaner, or a switch (more readability, a little less performance, though on such a function shouldn’t be a problem)
3) since, in any case, you seem to be calling this.SaveArticle(), you could call it only once, out of the IFs (would save some bytes), at the end.
4) Since you do not seem to be getting any result back from the SaveArticle function, we can understand that switching the label on the button does not depend on the returnedValue (and that you would switch label even with some silent error running in SaveArticle). Hence you should either switch the label before calling SaveArticle, or after adding a condition on the returnedValue of the SaveArticle
Just a point of view, I’m not writing this as guidelines eh
Ok, now i tried to find the bug… and I feel even more than what my previous comment was a good one
An “else” or a “switch” would have saved your life on this one hehehe