Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2010
    Location
    Toronto
    Posts
    95
    Thanks
    52
    Thanked 0 Times in 0 Posts

    Writing Javascript as OOP language-where are the sample scripts?

    I want to learn to write JavaScript in an object oriented way using constructor functions and prototypes. My problem is that even though I know the theory: prototypes, inheritance etc, I still think as a procedural programmer. Maybe if i could find enough examples on the web, I would change my way of thinking, but all articles on the web just present OOP for beginners.
    Is there a library on the web that includes OO scripts in JavaScript. my search did not produce desired results. thank you very much for helping me

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by chickentulip View Post
    Is there a library on the web that includes OO scripts in JavaScript. my search did not produce desired results. thank you very much for helping me
    Did you look through all the function and OO examples on javascriptexample.net?
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    chickentulip (02-14-2013)

  • #3
    New Coder
    Join Date
    Oct 2010
    Location
    Toronto
    Posts
    95
    Thanks
    52
    Thanked 0 Times in 0 Posts
    Thank you, I did not know about this web-site

  • #4
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    See for example this page Big integers which contains a script to work with.

    The problem was to pass from 2012 to 2013 with only to operands : the cube and the square root (with floor rounding). I find this 81 solutions with C++. However, this page performs all corresponding calculations with javascript ...

    The solutions n° 12 (with at most a number of 423 digits) and n°33 (with at most a number of 18 digits) are particularly remarkable...
    Last edited by 007julien; 02-14-2013 at 07:54 PM.

  • Users who have thanked 007julien for this post:

    chickentulip (02-14-2013)

  • #5
    New Coder
    Join Date
    Oct 2010
    Location
    Toronto
    Posts
    95
    Thanks
    52
    Thanked 0 Times in 0 Posts
    thank you, oo7julien. the more i look at these scripts the more i understand that it will take a long time before I will say I know Javascript

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    you can incorporate prototypal OOP into procedural code. That's a good way to start because you don't have to dive "all in". Most OOP is really just Class constructs, not message-passing OOP proper. Javascript too can have those class-based bundles of methods, properties, and events.

    I think the big diff is that prototypes can fully act more as global methods upon each data type; a method of a property doesn't makes sense in C as it does in JS. That you can upgrade your existing bundle in a different place entirely is a powerful possibility, and one that must be used responsibly.

    i think that to get going, look into turning some of your repetitive procedures into prototype methods. for example, you might have to calc an average often. Turn your avg-finding code into an Array prototype, and you can replace several repetitive procedural code sections with just one-line of code performing just one-call.

    I find that this allows more design flexibility than having to decide every capability of every object and property up-front. Furthermore, most of the generic prototypes you create for built-in types like String and Array can be cut-and-pasted into any project, without having to rename any handles or pointers, saving a TON of time.

    in short, don't rush; this stuff is complicated and takes a while to sink-in. I think that beefing up the built-in gives you a lot of custom power without forcing OOP conventions down your throat.

    i'd throw some examples your way, but im supposed to be getting ready for a valentine's dinner... cheers!
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    chickentulip (02-15-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •