Full JavaScript Object Model and Lexical Closures Overview

universit di pisa n.w
1 / 4
Embed
Share

Explore the JavaScript Object Model with examples on mapping strings to values, functions as first-class objects, and method properties. Delve into full lexical closures with a factorial function implementation. Understand JavaScript's permissiveness and object property manipulation.

  • JavaScript
  • Object Model
  • Lexical Closures
  • Functions
  • Properties

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Universit di Pisa JavaScript Object Model Giuseppe Attardi

  2. JavaScript in two slides Objects map strings to values (properties): var obj = new Object; obj["prop"] = 42; obj["0"] = hello ; Functions are first-class objects: function fact(n) { return (n == 0) ? 1 : n * fact(n-1); } fact.desc = "Factorial function"; => obj.prop => obj[0]

  3. JS in two slides (2) So methods are function-valued properties: obj.frob = function (n) { this.prop += n; }; obj.frob(6); Permissiveness throughout. Oops. grob = obj.frob; grob(6); prop = hello ; grob(6); => obj.prop == 48 => var not necessary => undefined + 6 == NaN => reset global prop => prop == hello6

  4. Full Lexical Closures Y = f. ( x. xx) ( x. f( v. (xx) v) Yfv = f(Yf) v function Y(f) { return function (x) { return x(x); }( function (x) {return f(function (v) { return x(x)(v); }); }); } var fact = Y(function (fact) { return function (n) { return (n == 0) ? 1 : n * fact(n-1); } }); fact(5); => 120

Related


More Related Content