Mnogim programerima JavaScript ne predstavlja osnovni programski jezik, već ga koriste ad-hoc, oslanjajući se na koncepte kojima su ovladali u drugim jezicima. To često može dovesti do zabune i do raznih iznenađenja, što dalje neopravdano razvija negativna osećanja prema JavaScript-u. Ova prezentacija otklanja deo te zabune i omogućava jasno razumevanje koncepta nasleđivanja u JavaScript-u
Snimak prezentacije: https://www.youtube.com/watch?v=pOaAraGnpZg
Roles are an excellent object-oriented tool both for allomorphism and for
reuse.
Roles facilitate allomorphism by favoring "does this object do X" versus "is
this object a subclass of X". You often care more about capability than
inheritance. In a sense, roles encode types better than inheritance.
Roles also provide an excellent faculty for reuse. This effectively eliminates
multiple inheritance, which is often the only solution for sharing code between
unrelated classes.
Roles can combine with conflict detection. This eliminates accidental shadowing
of methods that is painful with multiple inheritance and mixins.
Parameterized roles (via MooseX::Role::Parameterized) improve the reusability
of roles by letting each consumer cater the role to its needs. This does
sacrifice some allomorphism, but there are ways to restore it.
The document summarizes 10 new features in ECMAScript 2015 (ES6):
1. Default parameters allow defining function parameters that can be omitted when calling a function.
2. Rest parameters collect multiple function arguments into an array.
3. Spread syntax expands iterables like arrays into individual arguments.
4. Let and const introduce block scope and prevent redeclaration of variables.
5. Classes provide syntactic sugar over prototype-based inheritance.
6. Enhanced object literals allow omitting repeated name/value pairs and adding methods.
7. Template literals allow multiline strings and embedded expressions.
8. Object.assign copies enumerable own properties from one or more source objects to a target
The document discusses abstract syntax trees (ASTs) and parsing of code. It provides examples of parsing JavaScript code into tokens and then building a syntax tree. It also discusses common JavaScript parsers like Esprima and Acorn, and AST specifications like ESTree. Homomorphic parsing is shown where code and AST are equivalent. Common uses of ASTs include transpilation, linting, minification, and code transformation.
My JSConf.eu talk about next-gen JavaScript metaprogramming features, starting with ES5's new Object APIs and then focusing on the forthcoming Proxy object, approved for the next ECMA-262 Edition. This is beautiful work from Tom Van Cutsem and Mark Miller, with Andreas Gal helping on the implementation front -- proxies are already shipping in Firefox 4 betas.
This document provides an overview of JavaScript basics including:
- The history and creation of JavaScript in 2 weeks by Brendan Eich.
- Language basics like syntax, variables, objects, functions, and inheritance.
- Tools for JavaScript development like Firebug and jsLint for debugging and linting.
- Best practices like unobtrusive JavaScript, namespaces, and automated testing.
- Resources for further learning JavaScript like books and websites.
The document discusses good code practices and principles. It begins with an agenda that covers why code quality matters, object oriented principles like SOLID, code smells and heuristics for good code, and concludes with questions. Some key principles discussed include the single responsibility principle, open/closed principle, Liskov substitution principle, and interface segregation principle. Examples are given to illustrate how to apply these principles and improve code quality.
The document discusses using Rust and Emscripten to compile Rust code to JavaScript and WebAssembly. It covers how to export Rust functions, call JavaScript from Rust, and handle types through Embind to integrate Rust and JavaScript. Embind uses C++ templates to register Rust classes and implement bindings, allowing Rust code to interoperate with JavaScript through Emscripten.
The document provides an overview of JavaScript for PHP developers. It discusses similarities and differences between JavaScript and PHP syntax, including variables, arrays, conditionals, loops, functions, objects, prototypes, and more. It also summarizes the built-in JavaScript API, including global functions, constructors, and properties and methods of objects like Object, Array, Function, String, Number, Math, Date, and Error.
Roles are an excellent object-oriented tool both for allomorphism and for
reuse.
Roles facilitate allomorphism by favoring "does this object do X" versus "is
this object a subclass of X". You often care more about capability than
inheritance. In a sense, roles encode types better than inheritance.
Roles also provide an excellent faculty for reuse. This effectively eliminates
multiple inheritance, which is often the only solution for sharing code between
unrelated classes.
Roles can combine with conflict detection. This eliminates accidental shadowing
of methods that is painful with multiple inheritance and mixins.
Parameterized roles (via MooseX::Role::Parameterized) improve the reusability
of roles by letting each consumer cater the role to its needs. This does
sacrifice some allomorphism, but there are ways to restore it.
The document summarizes 10 new features in ECMAScript 2015 (ES6):
1. Default parameters allow defining function parameters that can be omitted when calling a function.
2. Rest parameters collect multiple function arguments into an array.
3. Spread syntax expands iterables like arrays into individual arguments.
4. Let and const introduce block scope and prevent redeclaration of variables.
5. Classes provide syntactic sugar over prototype-based inheritance.
6. Enhanced object literals allow omitting repeated name/value pairs and adding methods.
7. Template literals allow multiline strings and embedded expressions.
8. Object.assign copies enumerable own properties from one or more source objects to a target
The document discusses abstract syntax trees (ASTs) and parsing of code. It provides examples of parsing JavaScript code into tokens and then building a syntax tree. It also discusses common JavaScript parsers like Esprima and Acorn, and AST specifications like ESTree. Homomorphic parsing is shown where code and AST are equivalent. Common uses of ASTs include transpilation, linting, minification, and code transformation.
My JSConf.eu talk about next-gen JavaScript metaprogramming features, starting with ES5's new Object APIs and then focusing on the forthcoming Proxy object, approved for the next ECMA-262 Edition. This is beautiful work from Tom Van Cutsem and Mark Miller, with Andreas Gal helping on the implementation front -- proxies are already shipping in Firefox 4 betas.
This document provides an overview of JavaScript basics including:
- The history and creation of JavaScript in 2 weeks by Brendan Eich.
- Language basics like syntax, variables, objects, functions, and inheritance.
- Tools for JavaScript development like Firebug and jsLint for debugging and linting.
- Best practices like unobtrusive JavaScript, namespaces, and automated testing.
- Resources for further learning JavaScript like books and websites.
The document discusses good code practices and principles. It begins with an agenda that covers why code quality matters, object oriented principles like SOLID, code smells and heuristics for good code, and concludes with questions. Some key principles discussed include the single responsibility principle, open/closed principle, Liskov substitution principle, and interface segregation principle. Examples are given to illustrate how to apply these principles and improve code quality.
The document discusses using Rust and Emscripten to compile Rust code to JavaScript and WebAssembly. It covers how to export Rust functions, call JavaScript from Rust, and handle types through Embind to integrate Rust and JavaScript. Embind uses C++ templates to register Rust classes and implement bindings, allowing Rust code to interoperate with JavaScript through Emscripten.
The document provides an overview of JavaScript for PHP developers. It discusses similarities and differences between JavaScript and PHP syntax, including variables, arrays, conditionals, loops, functions, objects, prototypes, and more. It also summarizes the built-in JavaScript API, including global functions, constructors, and properties and methods of objects like Object, Array, Function, String, Number, Math, Date, and Error.
This was a talk given at HTML5DevConf SF in 2015.
Ever wanted to write your own Browserify or Babel? Maybe have an idea for something new? This talk will get you started understanding how to use a JavaScript AST to transform and generate new code.
The document discusses code for serial port (com) device drivers in FreeBSD. It shows code from the comstart() function, which is called by the tty layer when there is outgoing data to transmit. Comstart() grabs the data from the tty queue and sets up the com_softc structure to start transmission. It then calls the chip-specific transmit function. The com_softc structure contains a pointer to the associated tty structure.
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
If you're like me you remember the days of PHP3 and PHP4; you remember when PHP5 was released, and how it was touted to change to your life. It's still changing and there are some features of PHP 5.3 and new ones coming with PHP 5.4 that will improve your code readability and reusability. Let's look at some touted features such as closures, namespaces, and traits, as well as some features being discussed for future releases.
This document provides step-by-step instructions for cloning and building a Flappy Bird clone using Swift. It begins with setting up the project structure and basic gameplay elements like the background, ground and bird. It then adds parallax scrolling, bird animation and physics. Pipes and collision detection are implemented along with scoring. The document details many Swift concepts like classes, protocols and physics bodies to recreate the classic mobile game.
An introductory presentation I'm doing at my workplace for other developers. This is geared toward programmers that are very new to javascript and covers some basics, but focuses on Functions, Objects and prototypal inheritance ideas.
The document discusses various techniques for extending and improving Perl, including both good and potentially evil techniques. It covers Perl modules that port Perl 6 features to Perl 5 like given/when switches and state variables. It also discusses techniques for runtime introspection and modification like PadWalker and source filters. The document advocates for continuing to extend Perl 5 with modern features to keep it relevant and powerful.
Love it or hate it, JavaScript is playing an increasingly important role in the next generation of web and mobile apps. As code continues to move from the server to the client, JavaScript is being used to do more than simple HTML manipulation. Be prepared for this transition and make sure the JavaScript you write is optimized and ready to perform on desktops and devices! In this session, you will learn ten practical tips that you can use today to write faster, more maintainable, memory friendly JavaScript.
Practical JavaScript Programming - Session 1/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
The document discusses various techniques in Perl for dealing with reference cycles and memory leaks caused by strong references, including using weak references, extracting needed data from objects before destroying them, and passing objects into subroutines to avoid capturing them. It also discusses analogous techniques used in Objective-C like weak references and guard objects to break cycles.
This document discusses ways to prevent malicious Perl code from executing harmful actions by overriding core functions like die() and system() as well as by faking module imports. It explores how the Acme::BadExample module tries to perform dangerous tasks and ways Anti::Code can intervene to stop it without errors.
All projects start with a lot of enthusiasm. As many projects grow the technical debt gets bigger and the enthusiasm gets less. Almost any developer can develop a great project, but the key is maintaining an ever evolving application with minimal technical debt without loosing enthusiasm.
During this talk you will be taken on the journey of application design. The starting point is an application that looks fine but contains lots of potential pitfalls. We will address the problems and solve them with beautiful design. We end up with testable, nicely separated software with a clear intention.
Introduction to modern c++ principles(part 1)Oky Firmansyah
The document introduces modern C++ principles and smart pointers. It discusses how C++ is still actively used and evolved, and defines modern C++ as using new language features and libraries. It then covers smart pointers like unique_ptr, shared_ptr, and weak_ptr which help manage object lifetimes and avoid memory leaks. The document also discusses move semantics and perfect forwarding which allow efficient moving of objects. It provides examples of how RAII (Resource Acquisition Is Initialization) binds resource management to object lifetime through constructors and destructors.
This document discusses ECMAScript 2015 (ES2015), also known as ES6. It provides examples of new ES2015 features like arrow functions, template literals, classes, and modules. It also discusses how to set up a development environment to use ES2015, including transpiling code to ES5 using Babel, linting with Eslint, testing with Mocha, and generating coverage reports with Istanbul. The document emphasizes that while ES2015 is fun to explore, proper tooling like linting and testing is needed for serious development. It concludes by noting ES2015 marks a transition and thanks the audience.
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destructionFelipe Prado
1. The document discusses repurposing existing malware samples for offensive security purposes such as testing defenses or creating custom tools.
2. Specific examples analyzed include repurposing the OSX.FruitFly backdoor to specify custom command and control servers, repurposing the OSX.CreativeUpdate miner to change mining accounts, and repurposing the OSX.Keranger ransomware to use custom encryption and servers.
3. The techniques demonstrated include understanding malware capabilities, patching command and control protocols, avoiding antivirus detection, and creating new installers or payloads.
AST - the only true tool for building JavaScriptIngvar Stepanyan
The document discusses working with code abstract syntax trees (ASTs). It provides examples of parsing code into ASTs using libraries like Esprima, querying ASTs using libraries like grasp-equery, constructing and transforming ASTs, and generating code from ASTs. It introduces aster, an AST-based code builder that allows defining reusable AST transformations as plugins and integrating AST-based builds into generic build systems like Grunt and Gulp. Aster aims to improve on file-based builders by working directly with ASTs in a streaming fashion.
Mirah is a small, fast JVM language that uses Ruby syntax but compiles to Java bytecode. It was created by Charles Oliver Nutter, the creator of JRuby, who wanted to write Java code using a language as expressive as Ruby. Mirah has Ruby's syntactic sugar but is statically typed and compiled like Java, without runtime modification. It uses type inference and macros to provide Ruby-like conveniences while compiling to a small footprint without needing a runtime library, making it suitable for mobile applications. Developers can get started with Mirah by installing it with RVM and writing code that looks like Ruby but compiles to Java classes.
Have you ever thought, “I wish it was easier to change JavaScript code programmatically?” Maybe you wanted to write or edit a configuration block in source code. Perhaps you wanted to generate customized algorithmic code. For many, this kind of thing seems inaccessible.
The tools exist, though. In this talk, Stephen Vance will look at how he has used recast and esprima to edit and rewrite JavaScript code, leaving the untouched code completely intact, including whitespace and comments. At the end, you should have enough knowledge to be dangerous and start to write the next automatic programming, AI, take-over-the-world, self-improving software.
Things you should know about Javascript ES5. A programming language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else
This was a talk given at HTML5DevConf SF in 2015.
Ever wanted to write your own Browserify or Babel? Maybe have an idea for something new? This talk will get you started understanding how to use a JavaScript AST to transform and generate new code.
The document discusses code for serial port (com) device drivers in FreeBSD. It shows code from the comstart() function, which is called by the tty layer when there is outgoing data to transmit. Comstart() grabs the data from the tty queue and sets up the com_softc structure to start transmission. It then calls the chip-specific transmit function. The com_softc structure contains a pointer to the associated tty structure.
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
If you're like me you remember the days of PHP3 and PHP4; you remember when PHP5 was released, and how it was touted to change to your life. It's still changing and there are some features of PHP 5.3 and new ones coming with PHP 5.4 that will improve your code readability and reusability. Let's look at some touted features such as closures, namespaces, and traits, as well as some features being discussed for future releases.
This document provides step-by-step instructions for cloning and building a Flappy Bird clone using Swift. It begins with setting up the project structure and basic gameplay elements like the background, ground and bird. It then adds parallax scrolling, bird animation and physics. Pipes and collision detection are implemented along with scoring. The document details many Swift concepts like classes, protocols and physics bodies to recreate the classic mobile game.
An introductory presentation I'm doing at my workplace for other developers. This is geared toward programmers that are very new to javascript and covers some basics, but focuses on Functions, Objects and prototypal inheritance ideas.
The document discusses various techniques for extending and improving Perl, including both good and potentially evil techniques. It covers Perl modules that port Perl 6 features to Perl 5 like given/when switches and state variables. It also discusses techniques for runtime introspection and modification like PadWalker and source filters. The document advocates for continuing to extend Perl 5 with modern features to keep it relevant and powerful.
Love it or hate it, JavaScript is playing an increasingly important role in the next generation of web and mobile apps. As code continues to move from the server to the client, JavaScript is being used to do more than simple HTML manipulation. Be prepared for this transition and make sure the JavaScript you write is optimized and ready to perform on desktops and devices! In this session, you will learn ten practical tips that you can use today to write faster, more maintainable, memory friendly JavaScript.
Practical JavaScript Programming - Session 1/8Wilson Su
JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it.
“Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.
The document discusses various techniques in Perl for dealing with reference cycles and memory leaks caused by strong references, including using weak references, extracting needed data from objects before destroying them, and passing objects into subroutines to avoid capturing them. It also discusses analogous techniques used in Objective-C like weak references and guard objects to break cycles.
This document discusses ways to prevent malicious Perl code from executing harmful actions by overriding core functions like die() and system() as well as by faking module imports. It explores how the Acme::BadExample module tries to perform dangerous tasks and ways Anti::Code can intervene to stop it without errors.
All projects start with a lot of enthusiasm. As many projects grow the technical debt gets bigger and the enthusiasm gets less. Almost any developer can develop a great project, but the key is maintaining an ever evolving application with minimal technical debt without loosing enthusiasm.
During this talk you will be taken on the journey of application design. The starting point is an application that looks fine but contains lots of potential pitfalls. We will address the problems and solve them with beautiful design. We end up with testable, nicely separated software with a clear intention.
Introduction to modern c++ principles(part 1)Oky Firmansyah
The document introduces modern C++ principles and smart pointers. It discusses how C++ is still actively used and evolved, and defines modern C++ as using new language features and libraries. It then covers smart pointers like unique_ptr, shared_ptr, and weak_ptr which help manage object lifetimes and avoid memory leaks. The document also discusses move semantics and perfect forwarding which allow efficient moving of objects. It provides examples of how RAII (Resource Acquisition Is Initialization) binds resource management to object lifetime through constructors and destructors.
This document discusses ECMAScript 2015 (ES2015), also known as ES6. It provides examples of new ES2015 features like arrow functions, template literals, classes, and modules. It also discusses how to set up a development environment to use ES2015, including transpiling code to ES5 using Babel, linting with Eslint, testing with Mocha, and generating coverage reports with Istanbul. The document emphasizes that while ES2015 is fun to explore, proper tooling like linting and testing is needed for serious development. It concludes by noting ES2015 marks a transition and thanks the audience.
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destructionFelipe Prado
1. The document discusses repurposing existing malware samples for offensive security purposes such as testing defenses or creating custom tools.
2. Specific examples analyzed include repurposing the OSX.FruitFly backdoor to specify custom command and control servers, repurposing the OSX.CreativeUpdate miner to change mining accounts, and repurposing the OSX.Keranger ransomware to use custom encryption and servers.
3. The techniques demonstrated include understanding malware capabilities, patching command and control protocols, avoiding antivirus detection, and creating new installers or payloads.
AST - the only true tool for building JavaScriptIngvar Stepanyan
The document discusses working with code abstract syntax trees (ASTs). It provides examples of parsing code into ASTs using libraries like Esprima, querying ASTs using libraries like grasp-equery, constructing and transforming ASTs, and generating code from ASTs. It introduces aster, an AST-based code builder that allows defining reusable AST transformations as plugins and integrating AST-based builds into generic build systems like Grunt and Gulp. Aster aims to improve on file-based builders by working directly with ASTs in a streaming fashion.
Mirah is a small, fast JVM language that uses Ruby syntax but compiles to Java bytecode. It was created by Charles Oliver Nutter, the creator of JRuby, who wanted to write Java code using a language as expressive as Ruby. Mirah has Ruby's syntactic sugar but is statically typed and compiled like Java, without runtime modification. It uses type inference and macros to provide Ruby-like conveniences while compiling to a small footprint without needing a runtime library, making it suitable for mobile applications. Developers can get started with Mirah by installing it with RVM and writing code that looks like Ruby but compiles to Java classes.
Have you ever thought, “I wish it was easier to change JavaScript code programmatically?” Maybe you wanted to write or edit a configuration block in source code. Perhaps you wanted to generate customized algorithmic code. For many, this kind of thing seems inaccessible.
The tools exist, though. In this talk, Stephen Vance will look at how he has used recast and esprima to edit and rewrite JavaScript code, leaving the untouched code completely intact, including whitespace and comments. At the end, you should have enough knowledge to be dangerous and start to write the next automatic programming, AI, take-over-the-world, self-improving software.
Things you should know about Javascript ES5. A programming language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else
This document provides an overview of JavaScript for PHP developers. It compares the syntax and core concepts between the two languages. Some of the key points covered include: variables and data types are similar, functions are objects in JavaScript, JavaScript uses prototypes instead of classes, and functions provide scope. The document also summarizes the built-in global functions and properties, common methods for objects like Array and String, and emphasizes that constructor functions are often not needed in JavaScript.
This presentation will starts with an Introduction to object-oriented programming. And presentation main objective is to create javascript object and parse it in different way.
The document provides an overview of essential JavaScript concepts for survival including scope, literals and constructors, functions, and testing frameworks. It discusses best practices for declaring variables with var, using constructor functions and prototypes to create objects, encapsulating functions and data with closures, and popular JavaScript testing frameworks like QUnit, JSUnit, and Vows.
This document discusses new features in ECMAScript (ES) 6 including: enhanced object literals with shorthand property and method definitions; destructuring assignment for arrays and objects; template strings for string interpolation; iterators, generators, and for-of loops; modules with named and default exports; and the module loader API. It provides code examples to demonstrate these new features and compares them to CommonJS and ES5 syntax.
JavaScript - i och utanför webbläsaren (2010-03-03)Anders Jönsson
This document provides an overview of JavaScript concepts including variables, data types, objects, functions, conditionals, loops, callbacks, prototypes, this keyword, scope, closures, events, DOM manipulation, and asynchronous programming. It includes code examples to demonstrate these concepts such as defining variables, creating and accessing objects and their properties, writing functions with parameters and return values, if/else statements, for loops, and using callbacks with asynchronous functions.
This document provides examples and explanations of various JavaScript and TypeScript features including:
- Template literals and string interpolation
- let and const variable declarations
- Property shorthand syntax
- Object destructuring
- Spread operators
- Arrow functions
- Optional chaining
- Named exports and imports in ES modules
- Default exports in ES modules
- Fetching data with fetch API and promises
- Using the Axios library for HTTP requests
- Async/await syntax
- Mapping, filtering, and finding array elements
- Immutability with object and array methods
- Primitive and complex data types in TypeScript like interfaces, enums, and type aliases
js+ts fullstack typescript with react and express.pdfNuttavutThongjor1
The document provides an overview of various JavaScript and TypeScript features including:
1. Template strings, let/const, property shorthand, destructuring, spread operators, arrow functions, optional chaining, export/import syntax for ES modules, fetch API, Axios, async/await, and functional programming concepts like immutability, map, filter, find.
2. An introduction to TypeScript including setting up a project, primitive data types, interfaces, classes, functions, and union/intersection types.
3. Examples are provided to demonstrate many of these features like template strings, destructuring, spread operators, map/filter functions, and type aliases.
The document provides an overview of various JavaScript and TypeScript features including:
1. Template strings, let/const, property shorthand, destructuring, spread operators, arrow functions, optional chaining, named exports, default exports, fetch, axios, async/await, and classes.
2. TypeScript setup instructions, primitive data types, any/unknown, literal types, arrays, enums, interfaces, extending interfaces, readonly/optional properties, type aliases, function types, and union/intersection types.
3. Examples are provided to demonstrate many of these features such as mapping arrays, filtering arrays, finding values in arrays, immutable data structures, and more.
The document provides an agenda for a talk on modeling a Rubik's Cube in JavaScript. It begins with an introduction to scripting languages and ECMAScript. It then discusses modeling a Rubik's Cube by first walking through the code, then modeling the cube and finding moves to solve it. The document covers topics like scripting languages, ECMAScript, object-oriented programming concepts in JavaScript, and modeling a Rubik's Cube to be manipulated programmatically.
This document provides an introduction to advanced JavaScript concepts by Ryan Stout, including an overview of his background and experience, a history of JavaScript, explanations of core JavaScript concepts like types, objects, functions, closures, and prototypes, as well as discussions of tools for debugging, testing frameworks like Jasmine, and frameworks like jQuery, Underscore.js, and CoffeeScript.
This document provides an overview of ES6 features and how to set them up for use in Ruby on Rails applications. It describes key ES6 features such as let and const block scoping, template strings, destructuring assignment, default and rest parameters, loops and generators, enhanced object literals, Maps and Sets, arrow functions, modules, and classes. It then provides instructions for using the sprockets-es6 gem to transpile ES6 code to ES5 for use in Rails, as well as using Node.js and Gulp as an alternative approach.
This document summarizes some lesser known features of the ActionScript programming language. It begins by discussing various operators like equality, logical operators, and type casting. It then covers topics like namespaces, arguments, rest parameters, object references vs copies, and global functions. The document concludes by noting some gotchas and peculiarities in ActionScript, such as casting behaviors and behaviors of the Array and Date classes.
The document summarizes the key features of ECMAScript 6 (ES6), the 2015 version of JavaScript. Some of the major additions covered include let and const for block scoping, arrow functions, template strings, enhanced object properties, the spread operator, destructuring assignments, classes and inheritance, generators, and proxies. ES6 aims to make JavaScript a more robust and feature-rich programming language.
Web developers constantly look for the latest and greatest ways to hone their craft, but changes come fast. From jQuery to Angular to Ember to React, CoffeeScript to TypeScript, it seems there is always something new. But ES6 is something different. With ES6 we are seeing the evolution of core JavaScript. It includes syntactic improvements and great new features never before seen in client-side code. Linters and transpilers for ES6 are readily available and easy to use. There is no need to wait; learn how to leverage the power of "the new JavaScript" in your applications, today!
This document provides an overview of Node.js for PHP developers, comparing and contrasting features between the two languages/platforms. It covers key differences in variables, data types, operators, functions, classes/objects, modules and other concepts. The document aims to help PHP developers transition to Node.js by highlighting both similarities and differences at a conceptual level.
This document provides examples and explanations of JavaScript concepts including objects and arrays, functions and contexts, closures, inheritance, namespaces and scope, module patterns, and dispatching. It demonstrates creating and manipulating objects and arrays, defining functions, using closures, implementing inheritance with prototypes and Object.create, creating namespaces, revealing and constructor module patterns, and a publisher/subscriber dispatching example.
Similar to Prototypal inheritance in JavaScript (20)
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Takashi Kobayashi and Hironori Washizaki, "SWEBOK Guide and Future of SE Education," First International Symposium on the Future of Software Engineering (FUSE), June 3-6, 2024, Okinawa, Japan
What is Augmented Reality Image Trackingpavan998932
Augmented Reality (AR) Image Tracking is a technology that enables AR applications to recognize and track images in the real world, overlaying digital content onto them. This enhances the user's interaction with their environment by providing additional information and interactive elements directly tied to physical images.
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfUndress Baby
The quest for the best AI face swap solution is marked by an amalgamation of technological prowess and artistic finesse, where cutting-edge algorithms seamlessly replace faces in images or videos with striking realism. Leveraging advanced deep learning techniques, the best AI face swap tools meticulously analyze facial features, lighting conditions, and expressions to execute flawless transformations, ensuring natural-looking results that blur the line between reality and illusion, captivating users with their ingenuity and sophistication.
Web:- https://undressbaby.com/
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j
Dr. Jesús Barrasa, Head of Solutions Architecture for EMEA, Neo4j
Découvrez les dernières innovations de Neo4j, et notamment les dernières intégrations cloud et les améliorations produits qui font de Neo4j un choix essentiel pour les développeurs qui créent des applications avec des données interconnectées et de l’IA générative.
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppGoogle
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-fusion-buddy-review
AI Fusion Buddy Review: Key Features
✅Create Stunning AI App Suite Fully Powered By Google's Latest AI technology, Gemini
✅Use Gemini to Build high-converting Converting Sales Video Scripts, ad copies, Trending Articles, blogs, etc.100% unique!
✅Create Ultra-HD graphics with a single keyword or phrase that commands 10x eyeballs!
✅Fully automated AI articles bulk generation!
✅Auto-post or schedule stunning AI content across all your accounts at once—WordPress, Facebook, LinkedIn, Blogger, and more.
✅With one keyword or URL, generate complete websites, landing pages, and more…
✅Automatically create & sell AI content, graphics, websites, landing pages, & all that gets you paid non-stop 24*7.
✅Pre-built High-Converting 100+ website Templates and 2000+ graphic templates logos, banners, and thumbnail images in Trending Niches.
✅Say goodbye to wasting time logging into multiple Chat GPT & AI Apps once & for all!
✅Save over $5000 per year and kick out dependency on third parties completely!
✅Brand New App: Not available anywhere else!
✅ Beginner-friendly!
✅ZERO upfront cost or any extra expenses
✅Risk-Free: 30-Day Money-Back Guarantee!
✅Commercial License included!
See My Other Reviews Article:
(1) AI Genie Review: https://sumonreview.com/ai-genie-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIFusionBuddyReview,
#AIFusionBuddyFeatures,
#AIFusionBuddyPricing,
#AIFusionBuddyProsandCons,
#AIFusionBuddyTutorial,
#AIFusionBuddyUserExperience
#AIFusionBuddyforBeginners,
#AIFusionBuddyBenefits,
#AIFusionBuddyComparison,
#AIFusionBuddyInstallation,
#AIFusionBuddyRefundPolicy,
#AIFusionBuddyDemo,
#AIFusionBuddyMaintenanceFees,
#AIFusionBuddyNewbieFriendly,
#WhatIsAIFusionBuddy?,
#HowDoesAIFusionBuddyWorks
Using Query Store in Azure PostgreSQL to Understand Query PerformanceGrant Fritchey
Microsoft has added an excellent new extension in PostgreSQL on their Azure Platform. This session, presented at Posette 2024, covers what Query Store is and the types of information you can get out of it.
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsPeter Muessig
The UI5 tooling is the development and build tooling of UI5. It is built in a modular and extensible way so that it can be easily extended by your needs. This session will showcase various tooling extensions which can boost your development experience by far so that you can really work offline, transpile your code in your project to use even newer versions of EcmaScript (than 2022 which is supported right now by the UI5 tooling), consume any npm package of your choice in your project, using different kind of proxies, and even stitching UI5 projects during development together to mimic your target environment.
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j
Dr. Jesús Barrasa, Head of Solutions Architecture for EMEA, Neo4j
Découvrez les dernières innovations de Neo4j, et notamment les dernières intégrations cloud et les améliorations produits qui font de Neo4j un choix essentiel pour les développeurs qui créent des applications avec des données interconnectées et de l’IA générative.
E-commerce Development Services- Hornet DynamicsHornet Dynamics
For any business hoping to succeed in the digital age, having a strong online presence is crucial. We offer Ecommerce Development Services that are customized according to your business requirements and client preferences, enabling you to create a dynamic, safe, and user-friendly online store.
WhatsApp offers simple, reliable, and private messaging and calling services for free worldwide. With end-to-end encryption, your personal messages and calls are secure, ensuring only you and the recipient can access them. Enjoy voice and video calls to stay connected with loved ones or colleagues. Express yourself using stickers, GIFs, or by sharing moments on Status. WhatsApp Business enables global customer outreach, facilitating sales growth and relationship building through showcasing products and services. Stay connected effortlessly with group chats for planning outings with friends or staying updated on family conversations.
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
What is Master Data Management by PiLog Groupaymanquadri279
PiLog Group's Master Data Record Manager (MDRM) is a sophisticated enterprise solution designed to ensure data accuracy, consistency, and governance across various business functions. MDRM integrates advanced data management technologies to cleanse, classify, and standardize master data, thereby enhancing data quality and operational efficiency.
Measures in SQL (SIGMOD 2024, Santiago, Chile)Julian Hyde
SQL has attained widespread adoption, but Business Intelligence tools still use their own higher level languages based upon a multidimensional paradigm. Composable calculations are what is missing from SQL, and we propose a new kind of column, called a measure, that attaches a calculation to a table. Like regular tables, tables with measures are composable and closed when used in queries.
SQL-with-measures has the power, conciseness and reusability of multidimensional languages but retains SQL semantics. Measure invocations can be expanded in place to simple, clear SQL.
To define the evaluation semantics for measures, we introduce context-sensitive expressions (a way to evaluate multidimensional expressions that is consistent with existing SQL semantics), a concept called evaluation context, and several operations for setting and modifying the evaluation context.
A talk at SIGMOD, June 9–15, 2024, Santiago, Chile
Authors: Julian Hyde (Google) and John Fremlin (Google)
https://doi.org/10.1145/3626246.3653374
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
2. Object is not a primitive
{
name: 'John Doe',
married: false,
age: 25,
};
var person = console.log(person.name); // John Doe
3. Object is not a primitive
[ 1, 3, 5, 7, 9 ];var odd = console.log(odd.length); // 5
{
name: 'John Doe',
married: false,
age: 25,
};
var person = console.log(person.name); // John Doe
4. Object is not a primitive
[ 1, 3, 5, 7, 9 ];var odd = console.log(odd.length); // 5
/match-me/i;var regex = console.log(regex.ignoreCase); // true
{
name: 'John Doe',
married: false,
age: 25,
};
var person = console.log(person.name); // John Doe
5. Object is not a primitive
[ 1, 3, 5, 7, 9 ];var odd = console.log(odd.length); // 5
/match-me/i;var regex = console.log(regex.ignoreCase); // true
function (name) {
alert('Hello,' + name);
};
var greet = console.log(greet.length); // 1
{
name: 'John Doe',
married: false,
age: 25,
};
var person = console.log(person.name); // John Doe
6. Object is not a primitive
[ 1, 3, 5, 7, 9 ];var odd = console.log(odd.length); // 5
/match-me/i;var regex = console.log(regex.ignoreCase); // true
function (name) {
alert('Hello,' + name);
};
var greet = console.log(greet.length); // 1
{
name: 'John Doe',
married: false,
age: 25,
};
var person = console.log(person.name); // John Doe
var message = 'Welcome!';
var count = 0;
var flag = false;
7. Object is not a primitive
var blank = null;
var nothing = undefined;
[ 1, 3, 5, 7, 9 ];var odd = console.log(odd.length); // 5
/match-me/i;var regex = console.log(regex.ignoreCase); // true
function (name) {
alert('Hello,' + name);
};
var greet = console.log(greet.length); // 1
{
name: 'John Doe',
married: false,
age: 25,
};
var person = console.log(person.name); // John Doe
var message = 'Welcome!';
var count = 0;
var flag = false;
9. Theory of strings?!
var obj = {};
obj[null] = 42;
console.log(obj.hasOwnProperty('null'));
// true
console.log(obj['null']);
// 42
10. Theory of strings?!
var obj = {};
obj[null] = 42;
console.log(obj.hasOwnProperty('null'));
// true
console.log(obj['null']);
// 42
var a = ['zero','one','two'];
a['3'] = 'three';
console.log(a[1]);
// one
console.log(a['1']);
// one
console.log(a[3]);
// three
console.log(a['3']);
// three
console.log(a.length);
// 4
11. Theory of strings?!
var obj = {};
obj[null] = 42;
console.log(obj.hasOwnProperty('null'));
// true
console.log(obj['null']);
// 42
var a = ['zero','one','two'];
a['3'] = 'three';
console.log(a[1]);
// one
console.log(a['1']);
// one
console.log(a[3]);
// three
console.log(a['3']);
// three
console.log(a.length);
// 4
var a = ['x','y','z'];
a['test'] = 'array is object';
console.log(a['test']);
// array is object
console.log(a.length);
// 3
41. prototype property
console.log(typeof F);
// function
var F = function () {};
__proto__
function () {};
{
length: 0,
prototype
}
var F =
…
_ _proto_ _
{
constructor: F
}
…
console.log(typeof F.prototype);
// object
42. prototype property
console.log(typeof F);
// function
var F = function () {};
__proto__
function () {};
{
length: 0,
prototype
}
var F =
…
_ _proto_ _
{
constructor: F
}
…
console.log(typeof F.prototype);
// object
console.log(F.prototype.constructor === F);
// true
43. prototype property
console.log(typeof F);
// function
var F = function () {};
__proto__
function () {};
{
length: 0,
prototype
}
var F =
…
_ _proto_ _
{
constructor: F
}
…
console.log(typeof F.prototype);
// object
console.log(F.prototype.constructor === F);
// true
console.log(F.prototype.prototype);
// undefined
44. prototype property
console.log(typeof F);
// function
var F = function () {};
__proto__
function () {};
{
length: 0,
prototype
}
var F =
…
_ _proto_ _
{
constructor: F
}
…
console.log(F.prototype !== F._ _proto_ _);
// true
console.log(typeof F.prototype);
// object
console.log(F.prototype.constructor === F);
// true
console.log(F.prototype.prototype);
// undefined
46. prototype property & operator new
var F = function () {};
_ _proto_ _
{
constructor: F
}
__proto__
function () {};
{
length: 0,
prototype
}
var F =
……
47. prototype property & operator new
var F = function () {};
_ _proto_ _
{
constructor: F
}
__proto__
function () {};
{
length: 0,
prototype
}
var F =
……
var o = new F();
48. prototype property & operator new
new F();var o =
var F = function () {};
_ _proto_ _
{
constructor: F
}
__proto__
function () {};
{
length: 0,
prototype
}
var F =
……
var o = new F();
49. prototype property & operator new
new F();var o =
console.log(o._ _proto_ _ === F.prototype);
// true
var F = function () {};
_ _proto_ _
{
constructor: F
}
__proto__
function () {};
{
length: 0,
prototype
}
var F =
……
var o = new F();
50. prototype property & operator new
new F();var o =
console.log(o._ _proto_ _ === F.prototype);
// true
var F = function () {};
_ _proto_ _
{
constructor: F
}
__proto__
function () {};
{
length: 0,
prototype
}
var F =
……
new F();var p =
var o = new F();
51. prototype property & operator new
new F();var o =
console.log(o._ _proto_ _ === F.prototype);
// true
var F = function () {};
_ _proto_ _
{
constructor: F
}
__proto__
function () {};
{
length: 0,
prototype
}
var F =
……
new F();var p =
new F();var q =
var o = new F();
52. prototype property & operator new
new F();var o =
console.log(o._ _proto_ _ === F.prototype);
// true
var F = function () {};
_ _proto_ _
{
constructor: F
}
__proto__
function () {};
{
length: 0,
prototype
}
var F =
……
new F();var p =
new F();var q =
var o = new F();
54. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
55. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
,
print: function () {
console.log(this.val);
}
F.prototype.print = function () {
console.log(this.val);
};
56. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
,
print: function () {
console.log(this.val);
}
F.prototype.print = function () {
console.log(this.val);
};
var objX = new F(11);
57. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
,
print: function () {
console.log(this.val);
}
F.prototype.print = function () {
console.log(this.val);
};
var objX = new F(11);
{ val: 11 };var objX =
58. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
,
print: function () {
console.log(this.val);
}
F.prototype.print = function () {
console.log(this.val);
};
var objX = new F(11);
{ val: 11 };var objX =
objX.print(); // 11
59. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
,
print: function () {
console.log(this.val);
}
F.prototype.print = function () {
console.log(this.val);
};
var objX = new F(11);
{ val: 11 };var objX =
objX.print(); // 11
var objY = new F(45);
60. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
,
print: function () {
console.log(this.val);
}
F.prototype.print = function () {
console.log(this.val);
};
var objX = new F(11);
{ val: 11 };var objX =
objX.print(); // 11
var objY = new F(45);
{ val: 45 };var objY =
61. prototype property & operator new
var F = function (val) {
this.val = val;
};
{
constructor: F
}
function (val) {
this.val = val;
};
{
prototype
}
var F =
,
print: function () {
console.log(this.val);
}
F.prototype.print = function () {
console.log(this.val);
};
var objX = new F(11);
{ val: 11 };var objX =
objX.print(); // 11
var objY = new F(45);
{ val: 45 };var objY =
objY.print(); // 45
63. WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
64. WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
65. WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
66. WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
f.call(context, args); // context object
f.apply(context, [args]); // context object
67. WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
f.call(context, args); // context object
f.apply(context, [args]); // context object
f.call(null, args); // window
f.call(undefined, args); // window
68. WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
f.call(context, args); // context object
f.apply(context, [args]); // context object
f.call(null, args); // window
f.call(undefined, args); // window
f.call(42, args); // new Number(42)
69. WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
f.call(context, args); // context object
f.apply(context, [args]); // context object
f.call(null, args); // window
f.call(undefined, args); // window
obj.m(args); // obj
array[0](args); // array
f.call(42, args); // new Number(42)
70. var g = obj.m;
g(args);
WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
f.call(context, args); // context object
f.apply(context, [args]); // context object
f.call(null, args); // window
f.call(undefined, args); // window
obj.m(args); // obj
array[0](args); // array
f.call(42, args); // new Number(42)
71. var g = obj.m;
g(args);
WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
f.call(context, args); // context object
f.apply(context, [args]); // context object
f.call(null, args); // window
f.call(undefined, args); // window
obj.m(args); // obj
array[0](args); // array
// window
f.call(42, args); // new Number(42)
72. var g = obj.m;
g(args);
WTF is this?
var f = function (args) {
console.log(this);
};
var obj = { m: f };
var array = [ f ];
new f(args); // new object
f(args); // window
f.call(context, args); // context object
f.apply(context, [args]); // context object
f.call(null, args); // window
f.call(undefined, args); // window
obj.m(args); // obj
array[0](args); // array
What is this inside a function is determined when the function is invoked, not when it is defined!
// window
f.call(42, args); // new Number(42)
75. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
76. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
var g = function () {
// return null, undefined,
// or a primitive value
return -1;
};
77. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
new g(); // new object
g(); // -1 (null, undefined or primitive)
var g = function () {
// return null, undefined,
// or a primitive value
return -1;
};
78. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
new g(); // new object
g(); // -1 (null, undefined or primitive)
var h = function () {
return { val: 42 };
};
var g = function () {
// return null, undefined,
// or a primitive value
return -1;
};
79. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
new g(); // new object
g(); // -1 (null, undefined or primitive)
new h(); // { val: 42 }
h(); // { val: 42 }
var h = function () {
return { val: 42 };
};
var g = function () {
// return null, undefined,
// or a primitive value
return -1;
};
80. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
var wtf = function () {
return
{ val: 42 };
};
new g(); // new object
g(); // -1 (null, undefined or primitive)
new h(); // { val: 42 }
h(); // { val: 42 }
var h = function () {
return { val: 42 };
};
var g = function () {
// return null, undefined,
// or a primitive value
return -1;
};
81. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
var wtf = function () {
return
{ val: 42 };
};
new wtf(); // new object
wtf(); // undefined
new g(); // new object
g(); // -1 (null, undefined or primitive)
new h(); // { val: 42 }
h(); // { val: 42 }
var h = function () {
return { val: 42 };
};
var g = function () {
// return null, undefined,
// or a primitive value
return -1;
};
82. Something in return?
var f = function () {
return; // or w/o return
};
new f(); // new object
f(); // undefined
var wtf = function () {
return
{ val: 42 };
};
new wtf(); // new object
wtf(); // undefined ;
new g(); // new object
g(); // -1 (null, undefined or primitive)
new h(); // { val: 42 }
h(); // { val: 42 }
var h = function () {
return { val: 42 };
};
var g = function () {
// return null, undefined,
// or a primitive value
return -1;
};
84. Inherit from that
function create (that) {
}
var newObj = create(that);
var F = function () {};
return new F();
85. Inherit from that
function create (that) {
}
var newObj = create(that);
var F = function () {};
return new F();
{
constructor: F
}
function () {};
{
prototype
}
var F =
86. Inherit from that
function create (that) {
}
var newObj = create(that);
var F = function () {};
return new F();
{
constructor: F
}
function () {};
{
prototype
}
var F =
var that = {
…
}
87. Inherit from that
function create (that) {
}
var newObj = create(that);
var F = function () {};
return new F();
{
constructor: F
}
function () {};
{
prototype
}
var F =
var that = {
…
}
F.prototype = that;
88. Inherit from that
function create (that) {
}
var newObj = create(that);
var F = function () {};
return new F();
{
constructor: F
}
function () {};
{
prototype
}
var F =
var that = {
…
}{}var newObj =
F.prototype = that;
89. Inherit from that
function create (that) {
}
var newObj = create(that);
var F = function () {};
return new F();
var newObj = Object.create(that);
{
constructor: F
}
function () {};
{
prototype
}
var F =
var that = {
…
}{}var newObj =
F.prototype = that;
90. Inherit from that
function create (that) {
}
var newObj = create(that);
var F = function () {};
return new F();
var newObj = Object.create(that);
var newObj = Object.create(null);
{
constructor: F
}
function () {};
{
prototype
}
var F =
var that = {
…
}{}var newObj =
F.prototype = that;
108. function Object () {
[native code]
}
prototype
_ _proto_ _
{}
constructor
_ _proto_ _ = null
function Function () {
[native code]
}
prototype
_ _proto_ _
function () {}
constructor
_ _proto_ _
function MyFunction () {
// JavaScript code
}
prototype
_ _proto_ _
{}
constructor
_ _proto_ _
new MyFunction()
_ _proto_ _
new Object()
_ _proto_ _
109. • no classes – only objects and primitive values
• _ _proto_ _ vs. prototype
• one function = two objects
• this & return
• use F.prototype to share properties
• inherit from that
• instanceof vs. Object.isPrototypeOf()
• the map of Function and Object inheritance
• MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript
• Chrome DevTools: http://discover-devtools.codeschool.com
Takeaways
112. Polymorphism – Inheritance
// Base class providing common interface to all subclasses
var Vehicle = function (name, wheels) {
this.name = name;
this.wheels = wheels;
};
Vehicle.prototype.drive = function () {
console.log('Driving the ' + this.name + ' on ' + this.wheels + ' wheels');
};
// Subclass with additional methods, sharing the common interface
var Car = function (doors) {
this.superConstructor('car', 4);
this.doors = doors;
};
// Inherit the base class and keep a reference to the super class constructor
Car.prototype = Object.create(Vehicle.prototype);
Car.prototype.superConstructor = Vehicle;
// Specialized subclass methods
Car.prototype.checkDoors = function () {
console.log('This ' + this.name + ' has ' + this.doors + ' doors');
};
// Another subclass sharing the common interface
var Bicycle = function () {
this.superConstructor('bicycle', 2);
};
// Inherit the base class and keep a reference to the super class constructor
Bicycle.prototype = Object.create(Vehicle.prototype);
Bicycle.prototype.superConstructor = Vehicle;
// Example
var car = new Car(5);
var bicycle = new Bicycle();
car.checkDoors(); // This car has 5 doors
car.drive(); // Driving the car on 4 wheels
bicycle.drive(); // Driving the bicycle on 2 wheels
113. Polymorphism – Overloading
// Behavior depends on the number of supplied arguments
var argumentCounter = function() {
if (arguments.length <= 1) {
console.log('Processing at most one argument');
} else {
console.log('Processing multiple arguments');
}
};
// Behavior depends on the argument types
var typeChecker = function(arg) {
if (typeof arg === 'string') {
console.log('Processing a string argument');
} else {
console.log('Processing a non-string argument');
}
};
// Example
argumentCounter(); // Processing at most one argument
argumentCounter(1, 2, 3); // Processing multiple arguments
typeChecker('test'); // Processing a string argument
typeChecker(true); // Processing a non-string argument
114. Encapsulation
var House = function() {
var that = {},
privateRoom = function() {
console.log('in private');
};
that.publicRoom = function() {
console.log('entered public');
privateRoom();
console.log('exiting public');
};
return that;
};
// Example
var house = new House();
house.publicRoom(); // entered public
// in private
// exiting public
console.log('privateRoom' in house); // false
115. Aggregation
var Vehicle = function (name) {
return { name: name };
};
var Garage = function() {
var that = {}, vehicles = [];
that.add = function(vehicle) {
vehicles.push(vehicle);
console.log('Added ' + vehicle.name);
};
that.remove = function(vehicle) {
var found;
vehicles = vehicles.filter(function(v) {
found = found || vehicle === v;
return vehicle !== v;
});
console.log((found ? 'Removed ' : 'Could not remove ') + vehicle.name);
};
that.print = function() {
var names = vehicles.map(function(v) {
return v.name;
});
console.log('Vehicles: ' + names.join(', '));
};
return that;
};
// Example
var truck = Vehicle('truck');
var car = Vehicle('car');
var bicycle = Vehicle('bicycle');
var garage = Garage();
garage.add(car); // Added car
garage.add(bicycle); // Added bicycle
garage.print(); // Vehicles: car, bicycle
garage.remove(bicycle); // Removed bicycle
garage.remove(truck); // Could not remove truck
garage.print(); // Vehicles: car
116. Higher-order functions & collections
// Encapsulating iteration
function each(data, callback) {
for (var i = 0; i < data.length; i += 1) {
callback(data[i]);
}
}
// Mapping each value to a result
function map(data, operation) {
var result = [];
each(data, function(value) {
result.push(operation(value));
});
return result;
}
// Collecting only values satisfying the predicate
function filter(data, predicate) {
var result = [];
each(data, function(value) {
if (predicate(value)) {
result.push(value);
}
});
return result;
}
// Example
function increment(x) {
return x + 1;
}
function odd(x) {
return x % 2 === 1;
}
var data = [0, 1, 2, 3, 4];
console.log(map(data, increment)); // [1, 2, 3, 4, 5]
console.log(filter(data, odd)); // [1, 3]
117. Higher-order functions & composition
function compose (f, g) {
// Receive function arguments and/or return a function as the result
return function (x) {
return f(g(x));
};
}
// Example
function increment (x) {
return x + 1;
}
function times2 (x) {
return 2 * x;
}
var f = compose(increment, times2);
console.log(f(1)); // 3
console.log(f(2)); // 5
console.log(f(3)); // 7
118. Memoization
// Without memoization, the function may repeatedly
// compute the result for the same arguments
var fibonacciSlow = function fib (n) {
var result;
if (n < 2) {
result = n;
} else {
result = fib(n - 1) + fib(n - 2);
console.log('fibSlow(' + n + ') = ' + result);
}
return result;
};
// Example
fibonacciSlow(5);
// fibSlow(2) = 1
// fibSlow(3) = 2
// fibSlow(2) = 1
// fibSlow(4) = 3
// fibSlow(2) = 1
// fibSlow(3) = 2
// fibSlow(5) = 5
var fibonacci = (function () {
// Function keeps previously computed values in its private closure
// and returns the cached results when they are available
var memo = [0, 1];
return function fib (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = fib(n - 1) + fib(n - 2);
console.log('fib(' + n + ') = ' + result);
memo[n] = result;
}
return result;
};
}());
// Example
fibonacci(5);
// fib(2) = 1
// fib(3) = 2
// fib(4) = 3
// fib(5) = 5
119. Currying and partial function application
function curry (f) {
var slice = Array.prototype.slice;
var concat = Array.prototype.concat;
// Return the curried function f. The returned function is a "named
// anonymous function" or more precisely a named function expression.
// On the outside, the function is anonymous and its identifier 'curried'
// is accessible only from the inside of the function
return function curried () {
if (f.length > arguments.length) {
// If some arguments are still missing, save the supplied arguments
// and return a new function delegating back to this function, but
// with the additional arguments concatenated to the saved args
var args = slice.apply(arguments);
return function () {
return curried.apply(null, concat.apply(args, arguments));
};
}
// If the sufficient number of arguments is supplied, delegate to f
return f.apply(null, arguments);
};
}
// Example
function sum3 (a, b, c) {
return a + b + c;
}
s = curry(sum3);
console.log(s(1)(2)(3)); // 6
console.log(s(1)(2,3)); // 6
console.log(s(1,2)(3)); // 6
console.log(s(1,2,3)); // 6