January 10, 201412 yr Hi everyone Havent posted in a long time. First thank you all for the fantastic support you have given me ever sine i came here. Ok i need a little help. The OO is suppose to show a number for the article, a header title and a story but havent been able to get it to work I have been working on an OO that looks like this: Please help function myArticle(storyId, header, story) { this.storyId = storyId; this.header = header; this.story = story; var newNum = document.createElement("i"); var add_storyId = document.createTextNode(this.storyId); var newHeader = document.createElement("h2"); var add_header = document.createTextNode(this.header); var newPara = document.createElement("p"); var add_story = document.createTextNode(this.story); var getFooter = document.getElementById("footer"); document.body.insertBefore(Num,Story ,newPara, getFooter); } function init() { myNews = new storyId("1"); myNews = new header("The latest ne."); myNews = new story("The lwqdqqwd ewecew3 3332edew"); myNews.show(); }
January 10, 201412 yr Im not too sure exactly what you"re trying to acheive here. On a quick inspection i can't see anywhere in your code where you call the myArticle() constructor function. I know its not strictly necessary but all the DOM manipulation you have going on there would be simpler to impliment using jQuery. Edited January 10, 201412 yr by rbrtsmith
January 16, 201412 yr Try this function Article(storyId, header, story) { this.storyId = storyId; this.header = header; this.story = story; } function init() { var myArticle = new Article("1","The latest ne.","The lwqdqqwd ewecew3 3332edew") console.log(myArticle); } A few things.. Classes, i.e. Article, should have a capital as the first character, and drop the 'my', so myArticle -> Article By all means, when you create an instance of that object, by all means call it myArticle, see above for an example. Maybe its just been my experience but I would rewrite var newNum = document.createElement("i"); as var newNum = function(){document.createElement("i");} and call it via myArticle.newNum() This should get you started, constructing the object was your first, main problem Edited January 16, 201412 yr by pilgrim_fgau
Create an account or sign in to comment