May 22, 201214 yr Hello, all! I was trying to move object left-down-up-right and I have succedd without encapsulation, but now I'm trying to use javascript encapsulation and can't get any good result. All the time I get error: object required or object expected at line 14. Someone has a some idea what I'm doing wrong? You can see my code at: My link p.s.This is not a professional project, only a small test project for learnig javascript, because I'm real beginner. Edited May 22, 201214 yr by Lana9
May 22, 201214 yr Someone has a some idea what I'm doing wrong? You're actually using jsFiddle wrong. If you look in the top left-hand corner you'll see 2 dropdowns. These define the library to bring in and where to put your JavaScript code. At the moment you've got that set to MooTools and "onLoad" so all your code gets wrapped in the following: window.addEvent('load', function() { // Your code here }); This means that any variable you create inside that can't bee see anywhere other than that JavaScript box. To fix that, change the first dropdown to "no wrap (head)" and, since you're not using any libraries, change the second one to "No-Library (pure JS)"
May 22, 201214 yr Author You're actually using jsFiddle wrong. If you look in the top left-hand corner you'll see 2 dropdowns. These define the library to bring in and where to put your JavaScript code. At the moment you've got that set to MooTools and "onLoad" so all your code gets wrapped in the following: window.addEvent('load', function() { // Your code here }); This means that any variable you create inside that can't bee see anywhere other than that JavaScript box. To fix that, change the first dropdown to "no wrap (head)" and, since you're not using any libraries, change the second one to "No-Library (pure JS)" Hello Skateside, thank you for your response. I took your advice and done everything what you said, but I have a bunch of errors, still. Typeof: "Problem at line 14 character 20: Missing radix parameter. return parseInt(this.element.offsetLeft);". Also, I ran my code at PhpED, errors are the same. Of course, can't run code on button click, although /onclick event/ should call function for starting animation. This is how my animation should work(project with no encapsulation): My first project Edited May 22, 201214 yr by Lana9
May 22, 201214 yr Hello Skateside, thank you for your response. I took your advice and done everything what you said, but I have a bunch of errors, still. Typeof: "Problem at line 14 character 20: Missing radix parameter. return parseInt(this.element.offsetLeft);". Also, I ran my code at PhpED, errors are the same. Of course, can't run code on button click, although /onclick event/ should call function for starting animation. This is how my animation should work(project with no encapsulation): My first project The parseInt function is designed to interpret any number (or string that looks like a number) into a real integer. Usually it can successfully guess whether that's supposed to be base 10, 8 or 16, but occassionally it gets it wrong. To stop that, you can use the radix parameter to tell it how it should interpret the number. I'm guessing you want your number to be base 10, so here's how you say so: animWidth = parseInt(hello.offsetWidth, 10); What other errors are you getting?
May 22, 201214 yr Author The parseInt function is designed to interpret any number (or string that looks like a number) into a real integer. Usually it can successfully guess whether that's supposed to be base 10, 8 or 16, but occassionally it gets it wrong. To stop that, you can use the radix parameter to tell it how it should interpret the number. I'm guessing you want your number to be base 10, so here's how you say so: animWidth = parseInt(hello.offsetWidth, 10); What other errors are you getting? Now, I have only this two errors: Problem at line 26 character 34: Use '!==' to compare with 'null'. if(window.innerWidth != null){ Implied global: window 26,31,32. Thank you, a lot for your advices!!! This was really helpfull.
May 22, 201214 yr Now, I have only this two errors: Problem at line 26 character 34: Use '!==' to compare with 'null'. if(window.innerWidth != null){ Implied global: window 26,31,32. Thank you, a lot for your advices!!! This was really helpfull. The problem with != is that is can lie, when checking against things like null it will say it's the same as false or undefined. That's why the adive is to never compare with !=, but instead use !== if (window.innerWidth !== null) { As for the implied globals, it's tough to see what it could be refering to. Try moving your functions so they're declared before they're called, that might help.
Create an account or sign in to comment