javascript objects and functions

28

Upload: victor-verhaagen

Post on 08-Jul-2015

364 views

Category:

Documents


1 download

DESCRIPTION

JavaScript presentation for 24/i about Objects and Functions

TRANSCRIPT

Page 1: JavaScript objects and functions
Page 2: JavaScript objects and functions

JAVASCRIPTOBJECTS & FUNCTIONSVictor Perez

Page 3: JavaScript objects and functions

/ INTRODUCTION

Page 4: JavaScript objects and functions

⁄ ⁄ ⁄

● string, number, boolean, null and undefined

● Wrapper objects: String, Number and Boolean

● Object, Function, Boolean, Error, EvalError, RangeError, ReferenceError, SyntaxError,

TypeError, URIError, Number, Math, Date, String, RegExp, Array and JSON

● Host objects

● no class inheritance

● prototype inheritance

OBJECTSINTRODUCING

Page 5: JavaScript objects and functions

⁄ ⁄ ⁄

● Objects

● Function scope

● this and arguments

● constructor

● prototype

● return ( default: undefined )

FUNCTIONSINTRODUCING

Page 6: JavaScript objects and functions

/ OBJECTS

Page 7: JavaScript objects and functions

⁄ ⁄ ⁄

● literal

● constructor

● Object.create

CREATEOBJECTS

Page 8: JavaScript objects and functions

⁄ ⁄ ⁄

● Object.constructor

CONSTRUCTOROBJECTS

Page 9: JavaScript objects and functions

/ PROTOTYPE

Page 10: JavaScript objects and functions

⁄ ⁄ ⁄

● Inheritance

● Any object

● Prototype chain

● Read inheritance

● Write own property

INTRODUCTIONPROTOTYPE

Page 11: JavaScript objects and functions

⁄ ⁄ ⁄

EXAMPLEPROTOTYPE

Page 12: JavaScript objects and functions

⁄ ⁄ ⁄

EXAMPLEPROTOTYPE

Page 13: JavaScript objects and functions

⁄ ⁄ ⁄

● Object.create

PROTOTYPEOBJECTS

Page 14: JavaScript objects and functions

⁄ ⁄ ⁄

● Object constructor

PROTOTYPEOBJECTS

Page 15: JavaScript objects and functions

/ FUNCTIONS

Page 16: JavaScript objects and functions

⁄ ⁄ ⁄

● function statement

STATEMENTFUNCTIONS

Page 17: JavaScript objects and functions

⁄ ⁄ ⁄

● function expression

● The name is only available inside the

function

EXPRESSIONFUNCTIONS

Page 18: JavaScript objects and functions

⁄ ⁄ ⁄

● Function constructor

○ eval

○ global scope

CONSTRUCTORFUNCTIONS

Page 19: JavaScript objects and functions

/ THIS

Page 20: JavaScript objects and functions

⁄ ⁄ ⁄

GLOBAL CONTEXTTHIS

● Global object

● window in the browser

Page 21: JavaScript objects and functions

⁄ ⁄ ⁄

FUNCTION CONTEXTTHIS

● non strict

○ Global object

● strict mode

○ undefined

Page 22: JavaScript objects and functions

⁄ ⁄ ⁄

OBJECT METHODTHIS

● Object of the method

Page 23: JavaScript objects and functions

⁄ ⁄ ⁄

CONSTRUCTORTHIS

● Object of the new created object

Page 24: JavaScript objects and functions

⁄ ⁄ ⁄

CALL & APPLYTHIS

● First parameter will be bound to this

● call

● apply

● convert it to an object

Page 25: JavaScript objects and functions

⁄ ⁄ ⁄

BINDTHIS

● returns the same function where this is the same as the first parameter

● this can’t be changed

Page 26: JavaScript objects and functions

/ JAVASCRIPT

Page 27: JavaScript objects and functions

/ QUESTIONS?

Page 28: JavaScript objects and functions

THANKS