n341 de objectbasedjavascript

Upload: chandrashekargoud

Post on 04-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 n341 de ObjectBasedJavascript

    1/13

    Copyright 2005 Department of Computer & Information Science

    Object Based JavaScript

  • 7/29/2019 n341 de ObjectBasedJavascript

    2/13

    Copyright 2005 Department of Computer & Information Science

    Goals

    By the end of this lecture you should

  • 7/29/2019 n341 de ObjectBasedJavascript

    3/13

    Copyright 2005 Department of Computer & Information Science

    REVIEW: What is an object?

    An object is a unique programming entitythat has attributes to describe it andmethods to retrieve/set attribute values.

    We can create a blueprint of an objectcalled a class.

    We can create a usable instance of a classthrough instantiation.

  • 7/29/2019 n341 de ObjectBasedJavascript

    4/13

    Copyright 2005 Department of Computer & Information Science

    REVIEW: Encapsulation

    Data and the ways to get at that dataare wrapped in a single package, a

    class. The only way to access suchdata is through that package. Thisidea translates to information hiding.

  • 7/29/2019 n341 de ObjectBasedJavascript

    5/13

    Copyright 2005 Department of Computer & Information Science

    REVIEW: Inheritance

    Inheritance allows programmers tocreate new classes from existing

    ones.A child class inherits its properties

    and attributes from its parents, which

    programmers can change.

  • 7/29/2019 n341 de ObjectBasedJavascript

    6/13

    Copyright 2005 Department of Computer & Information Science

    REVIEW: Polymorphism

    Polymorphism describes howprogrammers write methods to do

    some general purpose function. Different objects might perform

    polymorphic methods differently.

  • 7/29/2019 n341 de ObjectBasedJavascript

    7/13

    Copyright 2005 Department of Computer & Information Science

    Is JavaScript Object-Oriented?

    Well, not really. Well call it Object-Based instead

    JavaScript uses objects by way ofsupporting inheritance andencapsulation, but it doesn't really

    provide support for polymorphism.

  • 7/29/2019 n341 de ObjectBasedJavascript

    8/13

    Copyright 2005 Department of Computer & Information Science

    Object-Based JavaScript

    We can create new, custom, re-usableobjects in JavaScript that include theirown methods, properties and events.

    Consider the following problem: I want torecord the color, brand, horsepower andprice of several cars.

  • 7/29/2019 n341 de ObjectBasedJavascript

    9/13

    Copyright 2005 Department of Computer & Information Science

    Solution Without Objects

    One solution to our problem is to relyon parallel arrays.

    However this can be confusing, as itcan be difficult to track with attributebelongs to which car

  • 7/29/2019 n341 de ObjectBasedJavascript

    10/13

    Copyright 2005 Department of Computer & Information Science

    Open the file calledobjectBasedProg_01.html

  • 7/29/2019 n341 de ObjectBasedJavascript

    11/13

    Copyright 2005 Department of Computer & Information Science

    What is an API?

    API stands forApplicationProgramming Interface.

    APIs allow programmers to extendthe current language to includedcustomized, re-usable components.

    Most modern languages incorporateAPIs.

  • 7/29/2019 n341 de ObjectBasedJavascript

    12/13

    Copyright 2005 Department of Computer & Information Science

    Open the files calledobjectBasedProg_02.html &carLib.js

  • 7/29/2019 n341 de ObjectBasedJavascript

    13/13

    Copyright 2005 Department of Computer & Information Science

    Summary