Jump to content

Jack McKalling

  • Posts

  • Joined

  • Last visited

Previous Fields

  • Languages
    PHP, (x)Html, CSS, JavaScript, XML, MySQL, C#, Java, RegExp

Contact Methods

  • Website URL

Profile Information

  • Gender

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Jack McKalling's Achievements

Dedicated Member

Dedicated Member (4/7)



  1. The javascript reference contains pages for all object types, like Array, Boolean, Date, Math, String. But not Object itself. There is a page for "Global" properties and functions, "Operators" and "Statements", but things like Object.create(), Object.values(), Object.keys() etc aren't on any of those pages either. Are these methods not documented because of lack of support on W3Schools for the relevant javascript version, or can Object be added to the reference pages? I'd like to see Object documented here, and not need to go to the MDN. Thanks for letting me know *Edit: I phrased it as a question, but it's really a suggestion, isn't it.
  2. For some reason the W3Schools website is not reachable in IE8. It simply gives a direct HTTP error and I cannot view any page. However the forum works just fine, but that is on a different domain anyway. Why is this? Is this a decision from W3S, to kick browsers that are too old, or is it some browser setting I myself overlooked? Because I find it very weird that W3S, who themselves are teaching how to be cross-browser, are not even compatible at all with this one. I was just trying to figure out whether I should be using the "lightgrey" or "lightgray" colourname, and I know IE8 is the browser that is specific on the difference, but I sadly cannot open this w3schools page about it in that browser because of this, or even any w3s page at all. I'm not necessarily asking for W3S to be compatible with IE8 if this is intended behavior, I know the browser is anciently old and I'm a dinosaur still trying to use it these days, but I just want to know why it is because this is strange. Thanks for your help.
  3. Hey, wonderful! New wow looks
  4. So you see, it all comes down to our definition. I never really agreed with wikipedias statement there because I thought OOP was only really a meaningful term if it is distinguised from classless programming (most languages work with objects anyway). This prototyping of JavaScript is quite different from my definition here, and though both methods could have their pros, I think I prefer the latter. But I don't want to start a discussion on which is better, I only need to point out I should have phrased myself from the start. Like this:Programmers who are (only) used to define classes like in e.g. C# or Java, will probably find the prototyping syntax of JavaScripts' OOP kind of weird. They are used to know what type every object is, more so because of the strongly-typed languages, rather than modifying the type from an instance pointer.Man I really hate explaining myself, I don't know why I'm so different.</OOP_subject>Aside from this advanced subject, I hope the return statement has become more clear to you now, newrehmi. Feel free to come back if needed.
  5. From my definition, prototyping has nothing to do with OOP. It may provide a means to create objects and such, but does this mean it is OOP? As previously mentioned JavaScript saves almost anything as objects. But compared to Java, C#, or even PHP's OOP implementation, JavaScript really isn't object oriented, right?Though it's often proven that some of my definitions are somewhat off to what's usually accepted, and that may apply here too. But it doesn't mean I never have my reasoning. I might seem off or backwards, and you're probably right, but when I mention OOP, I refer to using class definitions and inheritance etc. only, which is a much better way of programming if it were available in JavaScript. Prototyping is different, so this is my reason to say, prototyping, it is weird when you're experienced in "OOP". Am I using a different definition of OOP than you?You do agree with me class definitions are far better than prototyping, don't you? If so, then forget our definition differences as we'd be on the same line after all.It is not so important though, JavaScript doesn't know better, and I just mentioned my worthless opinion there.
  6. @ShadowMage,The reduction in parameters is what I also had in mind, but I thought just to first show the idea of parametering what was already global. I didn't know setTimeout() also accepts an anonymous function though, thanks! The tutorial doesn't explain the type of that argument quite clearly (they call it a "reference", but use a string in their own example). And what stupid of mine, default values of parameters, lol. I haven't been using either PHP or JavaScript for a while now, obviously I'm mixing things up a little here.I fully agree with you that the custom function is confusing. If you're an experienced OOP programmer like I am, the prototype and createDelegate() stuff of the JavaScript language really doesn't make any sense. thescientists example is much clearer on what it does, this actually begins to look like a conventional class definition!
  7. I believe you might write this function completely using parameters, eventhough you're using the setTimeout() function.Bear in mind the setTimeout() requires you to pass the function call as a string argument, as this means you can't simply pass in arguments to your function normally. You have to include the result of any argument into that string, which I present here: <script type='text/javascript'>//var text; //not necessary anymore//var texttobePlaced;//var theLoop = 0;function generateText(text="", textToBePlaced="", theLoop=0) { text = document.getElementById('thetext').value; var textlength = text.length - 1 if (theLoop <= textlength) { var randomSpeed = Math.round(Math.random()*200) texttobePlaced = text.charAt(theLoop); document.getElementById('text_place').innerHTML += texttobePlaced theLoop += 1; setTimeout('generateText("' + text + '","' + textToBePlaced + '",' + theLoop + ')',randomSpeed) } }</script> -You now don't need globals anymore (you'd have to test this though, haven't tried this much) because the variables are passed as arguments to the function every timeout.-I also added default values to the parameters, so if the function is called without arguments (i.e. the first time) they'll be initialised nevertheless.-Also notice you can use the "+=" operator to concatenate strings or increment integers.-Please notice the weird way of passing arguments in the setTimeout() function. The variables are concatenated to the string and embedded in double quotes if they represent a string themselves. This is important for it to work, as the scope of these variables is within the function where setTimeout() is called, not in the string of its argument. So you just have to concatenate them between the string. Again, you'd have to test this, this is only my second time I've tried it this way.
  8. I don't know if global variables make your browser slow, but it does provide the certain danger of conflicts between scripts that you installed together. A global variable should not be used by multiple functions unintentionally, and if they are global, this is precisely what would be possible.In my opinion, it should always be visible where a variable comes from, and in what scope it is active. In OOP this is quite obvious if you fully qualify them, but in javascript, there is no such thing. So to keep things readable, I'd say just try to use just the one scope of every function, and not the global one, for declaring variables. Naming conventions might work to "qualify" a variable visibly, but wouldn't syntactically.@boen_robot: you got me there... glad that I'm not concerned about this in my work
  9. That's right. I totally forgot about "normal use" of objects and assumed the use was referring to OOP.I think my only use for global variables is/was for preloading images with javascript, but then again, I don't use that anymore either because of the sprite-technique.My own reasoning behind not recommending global variables is that this scope is used to declare functions only, in the head section of your page. I see this section as a declaration of modules, and no actual execution of code.
  10. But I suppose if multiplication or addition is all you want, you probably don't need both of these values returned by the same function at the same time. For other cases, this is the way to do it though.There is another option to 'return' multiple values, but this is more like a hack and better done in OOP context.You can instead of hard returning a value, also change a variable or property that was created outside the function scope. If you change such a value from within the function, you don't need to return it from the function as it is already avaliable outside. This is not recommended programming though. If such variable management is necessary, consider learning the way of OOP programming instead. OOP stands for Object Oriented (Programming), and is what (I think) Deirdre's_Dad refers to with "using objects".
  11. Correct, the return-statement returns code execution, so really any code that follows it is skipped. You cannot return multiple values precisely because of this, the only way of doing so would be by combining the values in one value, like an array (like Deirdre's_Dad explains below). You can also make the calc(x,y) function callable with a third parameter that is of boolean value, to indicate whether you want to add or multiply, and return the appropriate value by conditioning on the value of this parameter. <head><script type='text/javascript'>function calc(x,y,multiply) { var sum = x + y; var rum = x * y; if (multiply == true) return rum; //else return sum; }document.write(calc(5,2,false)); //7document.write(calc(5,2,true)); //10</script></head> There are a lot of different ways to write this function. In my example here I've chosen an IF-condition to check on the value of the third parameter, but you could also use a conditional statement to compress this into one line: <head><script type='text/javascript'>function calc(x,y,multiply) { var sum = x + y; var rum = x * y; return (multiply == true) ?rum :sum; }document.write(calc(5,2,false)); //7document.write(calc(5,2,true)); //10</script></head> Or if this code is all you need, even more compressed: <head><script type='text/javascript'>function calc(x,y,multiply) { return (multiply == true) ?x*y :x+y; }document.write(calc(5,2,false)); //7document.write(calc(5,2,true)); //10</script></head> (notice I check the value of the multiply parameter if it is of boolean TRUE, you could also leave the equality check if you're sure the parameter is always a boolean)
  12. Just as I explained, the onsubmit handler is using a value. If you return false from it, it will of cource cancel the event, but if you only call a function, it will not, regardless of the return value of that function. Unless you RETURN the return-value of the function like in above example :)This might seem a little weird for you in the beginning. But this eventhandler is, if you want to know, a separate code scope from the event itself. It will only cancel the event if it returns a value, just like your function does. If the handler calls a function itself, the return value must be returned from the handler too.
  13. You'll also want to return the value of the function to the event itself, simply calling it won't be enough in my experience.Using your example, the code will look like the following, taking ShadowMage's correct suggestion in account: <head><script type='text/javascript'>function denySubmit() { alert('you will not going anywhere'); //but the the form will now NOT load the 'lol.php' return false; }</script></head><body><form action='lol.php' method='get' onsubmit='return denySubmit()'><input type='text' name='myText' /><input type='submit' /></form></body> The reason for this, is that the onsubmit attribute of the form-element, is just a handler. When the event occurs, the handler will first be called, and as it calls another function, the return value of your function must be returned from the handler to the event itself to cancel the event.I also added a name attribute to your textfield, as that will be the accessible name for this field within lol.php. You can also choose to use the POST method instead of GET, if you want to be save and not overflow or expose the data in the URL.To add to ShadowMage's reply, the return-statement is used to return code execution from anywhere within a function back to wherever it was called, and returning a value with it is only optional. You can for instance also return from a function if a certain condition is met, to prevent the rest of the function. A simple example below: function test(){ if (document.getElementById("myCheckbox").checked != "true") return; //this code will not be executed it the checkbox is not checked document.forms[0].submit();} If your function is returning a value, you can use this value when you call it, just as if the function call were a variable or property. Doing so will require the function to always return a value though, and result in an error if it for some reason doesn't.
  14. Hello,I'm new to using (MySQL) databases through Eclipse, and would like to know how it's done.Currently I have my project for a windows application. It's fully written in Java. But to distribute the app, I'm using an executable wrapper that packs up the jar and necessary files into one exe, and then I rar it along with some gfx and sfx folders into one nice archive. The idea is that I further develop this windows application using a MySQL database (which I hereby want to start using), untill I port it to an applet for websites and then switch to an existing online MySQL server. If it is possible, I actually like to keep both windows distribution and website applet separately available using their own database when it comes to that.Because I'm having the (MySQL using) applet in mind, I think I should start with implementing a MySQL database. I'm not familiar with other DBMSs. But if there is a portable solution for another DBMS, please tell me.One of my questions would be, do I need to install the Connector/J to be able to use a MySQL database, or did the driver come bundled with Eclipse? As I just recently installed the Indigo version and got the Connector/J driver from mysql.org, but I don't know what to do with the latter. I researched myself, but can't find a simple answer. I know that NetBeans is bundled with these type4 drivers, so if Eclipse isn't, why not?So if I want to start using a database, keeping in mind it will eventually be redirected to an existing online one, what DBMS options do I have, should I use a bridge or not, what else do I need, and how do I do it? Please help Thanks,Jack
  15. You're right about the origin of this account, did you remember that? But you're slightly inaccurate about the irony part. We had an aggreement that I should take over all of his work and memberships, and continue on his ideas for a website. I quite did not force it, in fact, I was given permission. This was all a long time ago though, long before the post you refer to.It may seem a little confusing, I understand. But I don't really want to talk about the origin. I'm the only one now, and anything that has recently come up as one of my threads is in fact really mine. I wouldn't have posted my alias name in that post though, if I knew it would be used elsewhere. I should have thought about that better then. It is much more about the history of the name that I invented rather than the post it is in.I feel some of you don't understand or share the same value as I do, and I respect that. I don't need to persuit this further if I don't want to, but please do understand that there is thus more to the name than initially obvious. I chose an alias because of the same reason why the original owner requested my intervention in the first place. So I do feel bound to protect it.*Edit:I'll just remove my name there to prevent any further mishaps.
  • Create New...