ECMAScript 3.1 Object Model Allen Wirfs-Brock Microsoft.

Slides:



Advertisements
Similar presentations
the javascript language BY SA.
Advertisements

1 User-Defined Classes The String class is a pre-defined class that is provided by the Java Designer. Sometimes programmers would like to create their.
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
ECMAScript 5: The New Parts Level 7. Complete implementations of ECMAScript, Fifth Edition, are now in the best web browsers. Including IE10.
Road Map Introduction to object oriented programming. Classes
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Object-Oriented Application Development Using VB.NET 1 Chapter 7 Adding Responsibilities to Problem Domain Classes.
OBJECTS MIT-AITI copyright Introduction Object and Properties Constructors and Methods Prototypes and Inheritance Object-Oriented JavaScript Objects.
IS JAVASCRIPT OBJECT-ORIENTED? Contains objects Data Methods Doesn’t have classes Does have constructors Does have prototype functions Doesn’t provide.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
JavaScript: The Language Andrew Miadowicz Program Manager DEV307.
How Java becomes agile riding Rhino Xavier Casellato VP of engineering, Liligo.com.
JavaScript davide morelli history LiveScript (1995) in Netscape java script is a misleading name started as a scripting counterpart.
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
E FFECTIVE C# 50 Specific Ways to Improve Your C# Second Edition Bill Wagner محمد حسین سلطانی.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Changes to JavaScript, Part 1: EcmaScript 5 Mark S. Miller, Waldemar Horwat, Mike Samuel Your EcmaScript committee representatives.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Martin Kruliš by Martin Kruliš (v1.0)1.
Object Oriented Programming (OOP) Lecture No. 10.
Prototypal Inheritance. Can We Do Inheritance Without Classes? How do we share behaviour across objects.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
CNIT 133 Interactive Web Pags – JavaScript and AJAX Objects.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
MASTERING NAMESPACES! Илья Кантор EcmaScript 5.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Composition 1.  recall that an object of type X that is composed of an object of type Y means  X has-a Y object and  X owns the Y object  in other.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
JavaScript and Ajax (JavaScript Arrays) Week 5 Web site:
CSE 1020:Using Objects Mark Shtern 1-1. Summary Read API Method binding and overloading Development process Input validation Assert 1-2.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Martin Kruliš by Martin Kruliš (v1.1)1.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Re-Intro to Object Oriented Programming
Creating Your Own Classes
Inheritance ITI1121 Nour El Kadri.
OOP Powerpoint slides from A+ Computer Science
Modern JavaScript Luke Hoban Program Manager — JavaScript
Juriy Bura
CS 302 Week 11 Jim Williams, PhD.
Classes In C#.
Abstract Data Types and Java Classes
ARRAYS MIT-AITI Copyright 2001.
البرمجة بلغة الفيجول بيسك ستوديو
البرمجة بلغة فيجول بيسك ستوديو
CS212: Object Oriented Analysis and Design
CSE 1030: Implementing Mixing static and non-static features
JavaScript: The Language
תירגול 9 אובייקטים.
Modern JavaScript Develop And Design
CS 302 Week 9 Jim Williams.
Copy Assignment CSCE 121 J. Michael Moore.
CS5220 Advanced Topics in Web Programming JavaScript Basics
© A+ Computer Science - OOP © A+ Computer Science -
CS5220 Advanced Topics in Web Programming Node.js Basics
CS3220 Web and Internet Programming JavaScript Basics
Functions, Return Values, Parameters Getters and Setters
CIS 199 Final Review.
Functions, Return Values, Parameters Getters and Setters
Object-Oriented Programming: Classes, Inheritance, and Interfaces
CS3220 Web and Internet Programming JavaScript Basics
Copy Assignment CSCE 121.
ITE “A” GROUP 2 ENCAPSULATION.
JavaScript Internals and OOP Concepts
Presentation transcript:

ECMAScript 3.1 Object Model Allen Wirfs-Brock Microsoft

Value Attributes (ReadOnly,DontEnum,DontDelete) Property Name [[Prototype]] Various internal properties. "foo" “2" “1" 42.0 undefined " doWork" An Object ECMAScript 3 Object Model “1" An Object A Function (closure) Value Attributes (ReadOnly,DontEnum,DontDelete) Property Name [[Prototype]] Various internal properties. " constructor"DontEnum " toString"DontEnum A Prototype Object " 1" " prototype" Value Attributes (ReadOnly,DontEnum,DontDelete) Property Name [[Prototype]] Various internal properties. ReadOnbly,DontEnum,DontDelete" length" ReadOnbly,DontEnum,DontDelete A Constructor Function

ES3.1 Object Model Changes Rename/repurpose attributes – ReadOnly → Writable – DontEnum -> Enumerable – DontDelete -> Configurable Attribute values are programmatically settable and testable An object may be programmatically marked as “nonExtensible” (properties may not be added) Accessor Properties (getter/setter)

Configurable Attribute The [[configurable]] attribute of a property controls whether the definition of an attribute can be programmatically changed: – Delete the attribute – Change the state of a property attribute: writable, enumerable, configurable – Change/delete the getter and/or setter function of an accessor property. – Convert a data property to an accessor property or visa versa. If Configurable attribute is false for a property – None of the above can occur – Writable can be change from true to false

Manipulating Properties and Attributes “Static” functions accessed via Object constructor – Object.defineProperty(obj, propName, propDescriptor) – Define a property: Object.defineProperty(o, “length”, { getter: function() {return this.computeLength()}, setter: function(value){this.changeLength(value)} }); Object.defineProperty(o, “1”, {value: 1, enumerable: true, configurable: true}); – Modify property attributes Object.defineProperty(Array.prototype, “forEach”, {enumerable: false, writable:false, configurable: false});

Retrieving a Property Definition – Object.getOwnPropertyDescriptor (obj, propName) var desc = Object. getOwnPropertyDescriptor(o, “length)); – Return value isdescriptor with data properties value, writeable, enumerable, configurable or getter, setter, enumerable, configurable – Return value is usable as 3 rd argument to Object.defineProperty

Object Lock-down Prevent adding properties to an object – Object.preventExtensions(obj ) Prevent adding or reconfiguring properties – Object.seal(obj) Prevent adding, reconfiguring, modify the value of properties – Object.freeze(obj)

Other Object Meta Methods Object.defineProperties(obj, propName, descriptorSet) Object.create(protoObj, descriptorSet); Object.getOwnPropertyNames(obj) Object.getPrototypeOf(obj) Object.isExtensible(obj) Object.isSealed(obj) Object.isFrozen(obj)

Example // a Point “class”. function Point(x, y) { const self = Object.create(Point.prototype, { toString: {value: Object.freeze(function() { return ' ')}}, enumerable: true}, getX: {value: Object.freeze(function() {return x}), enumerable: true}, getY: {value: Object.freeze(function() {return y}), enumerable: true} }); return self; }

Example //Point as a non-final non-abstract root/mixin class where toString is a final method: function PointMixin(self, x, y) { Object.defineProperties(self, { toString: {value: Object.freeze(function() { return' ')}}, enumerable: true}, getX: {value: Object.freeze(function() {return x}), enumerable: true, flexible: true}, getY: {value: Object.freeze(function() {return y}), enumerable: true, flexible: true} }); } function Point(x, y) { const self = Object.create(Point.prototype); // only for instanceof PointMixin(self, x, y); return Object.freeze(self); } Object.freeze(PointMixin); Object.freeze(Point.prototype); Object.freeze(Point);