JavaScript for .NET Developers

Book description

Unlock the potential of evergreen browsers and increase the efficiency of your ASP.NET applications by learning how to write JavaScript

About This Book

  • Boost your skillset and start bringing JavaScript into your web development projects
  • Leverage your existing ASP.NET knowledge to develop dynamic and responsive SPAs
  • Learn effective design patterns for sustainable, and scalable web development

Who This Book Is For

This book is for ASP.NET developers that want to bring JavaScript into their skillset to build applications that are truly dynamic and responsive. It's for developers who are focused on developing for users who want to deliver a great end product and a fantastic experience.

What You Will Learn

  • Get to grips with the basic to advanced concepts of JavaScript
  • Learn how to use JavaScript on server side using Node.js
  • Develop web applications in ASP.NET using JavaScript
  • Get to know with industry-wide best practices and design patterns that provide maintainability and scalability
  • Build an ASP.NET application using Angular 2 with TypeScript and Web API
  • Explore WinJS and see how to use mobile capabilities from web applications
  • Use JavaScript to develop scalable ASP.NET applications
  • See how to test and debug JavaScript

In Detail

If you want to improve responsiveness or the UX in your ASP.NET applications, JavaScript can be a life saver. In an age where server-side operations have shifted to the client, being able to handle JavaScript with confidence and fluency is vital for ASP.NET developers. There's no point trying to fight it, so start learning with this book. Make sure your projects exceed user expectations.

Begin by getting stuck into the basics of JavaScript, and explore the language in the context of ASP.NET Core. You'll then find out how to put the principles into practice, as you learn how to develop a basic ASP.NET application using Angular 2 and TypeScript. You'll also develop essential skills required to develop responsive apps, with a little help from AJAX, ensuring that you're building projects that can be easily accessed across different devices.

With guidance on Node.js and some neat techniques to test and debug a range of JavaScript libraries in Visual Studio, you'll soon be well on your way to combining JavaScript with ASP.NET in a way that's capable of meeting the challenges of modern web development head-on.

Style and approach

This book will build the skillset of every .NET developer, so they can build stronger and more responsive web apps with confidence.

Table of contents

  1. JavaScript for .NET Developers
    1. Table of Contents
    2. JavaScript for .NET Developers
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. JavaScript for Modern Web Applications
      1. Importance of JavaScript
        1. What is JavaScript?
        2. Comparing runtimes
      2. Setting up your environment
        1. New editing experience of JavaScript in Visual Studio 2015 IDE
      3. Programming in JavaScript
        1. Core fundamentals of JavaScript
          1. Adding JavaScript to an HTML page
          2. Statements in JavaScript
          3. Literals and variables
          4. Data types
            1. Array in JavaScript
          5. What is JSON?
            1. Simple objects in JSON
            2. Declaring arrays in JSON
            3. Nesting data in JSON
          6. Conversions in data types
        2. Elements of JavaScript
          1. Constants in JavaScript
          2. Comments
          3. Case sensitivity
          4. Character set
        3. Expressions
          1. The this keyword
          2. Sequence of code execution in JavaScript
          3. Using the this keyword on a calling method
          4. The function statement and expression
          5. Class statement and expression
          6. Grouping operator
          7. new
          8. super
        4. Operators
          1. Assignment operators
          2. Arithmetic operators
          3. Unary operators
          4. Comparison operators
            1. Strict equal operator
            2. Strict not equal operator
          5. Logical operators
            1. Logical AND
            2. Logical OR
            3. Logical NOT
          6. Bitwise operators
            1. Bitwise AND
            2. Bitwise OR
            3. Bitwise NOT
            4. Bitwise XOR
          7. Bitwise shift operators
            1. Bitwise left shift
            2. Bitwise right shift
          8. The typeof operator
          9. The void operator
          10. The delete operator
          11. Miscellaneous operators
            1. Conditional operators
            2. Spread operator
        5. Built-in display methods in JavaScript
          1. Displaying messages
            1. Alert box
            2. Confirm box
            3. Prompt box
          2. Writing on a page
          3. Writing into the browser's console window
        6. Browser Object Models in JavaScript
          1. Window
          2. Document
          3. Navigator
            1. Properties
          4. Screen
            1. Properties
          5. History
            1. Methods
          6. Location
            1. Properties
            2. Methods
      4. Summary
    9. 2. Advanced JavaScript Concepts
      1. Variables – scope and hoisting
        1. Declaring let
          1. Conditions where let is efficient to use
            1. Functions in loops
      2. Events in JavaScript
      3. Function arguments
      4. Object-oriented programming in JavaScript
        1. Creating objects
          1. Defining objects using object literal notation
          2. Defining objects using a constructor pattern
            1. Using the class keyword
          3. Properties
            1. Defining properties using object literal notation
            2. Defining properties using a constructor pattern
            3. Defining properties using setters/getters in ECMAScript 6
            4. JavaScript property descriptors
              1. Display property descriptors
              2. Managing property descriptors
              3. Using getters and setters
          4. Methods
            1. Defining methods through object literal notation approach
            2. Defining objects using the constructor function approach
          5. Extending properties and methods
          6. Private and public members
          7. Inheritance
            1. Chaining constructors in JavaScript
            2. Inheritance using Object.create()
            3. Predefined properties of Object.create()
            4. Defining inheritance using class
          8. Encapsulation
          9. Abstraction
          10. new.target
          11. Namespace
        2. Exception handling
          1. Error
          2. RangeError
          3. ReferenceError
          4. SyntaxError
          5. TypeError
          6. URIError
        3. Closures
          1. Practical use
        4. JavaScript typed arrays
          1. Typed array architecture
            1. The array buffer
            2. Creating a buffer
        5. Maps, sets, weak maps, and weak sets
          1. Maps and weak maps
          2. Sets and weak sets
          3. The strict mode
      5. Summary
    10. 3. Using jQuery in ASP.NET
      1. Getting started with jQuery
        1. Using a content delivery network
          1. The use of CDN
        2. The document ready event
        3. The jQuery selectors
          1. Selecting the DOM elements using the ID
          2. Selecting the DOM elements using TagName
          3. Selecting nodes by the class name
          4. Selecting by the attribute value
          5. Selecting input elements
          6. Selecting all the elements
          7. Selecting the first and last child elements
          8. The contains selector in jQuery
          9. Selecting the even and odd rows selectors
        4. Manipulating DOM
          1. Modifying an element's properties
          2. Creating new elements
          3. Removing elements and attributes
        5. Event handling in jQuery
          1. Registering events in jQuery
          2. Binding events using on and off
          3. Using the hover events
      2. Summary
    11. 4. Ajax Techniques
      1. Introducing Ajax
        1. How Ajax works
          1. Ajax requests using the classic XHR object
            1. XHR methods
            2. XHR events
            3. XHR properties
          2. Making an Ajax request using jQuery
            1. jQuery.ajax()
          3. Ajax properties
            1. Pre-filtering Ajax requests
            2. Setting default values for all future Ajax requests
          4. Loading data through the get functions in jQuery
            1. Using jQuery.get()
            2. Using jQuery.getJSON()
            3. Using jQuery.getScript()
          5. Posting data to server using the post function
          6. Ajax events
            1. Local events
            2. Global events
        2. Cross-origin requests
          1. JSON-P
            1. Using JSON-P
          2. CORS
            1. Specifying the CORS policy at services level
            2. Enable CORS at the Configure method
      2. Calling WCF services from JavaScript
      3. Summary
    12. 5. Developing an ASP.NET Application Using Angular 2 and Web API
      1. TypeScript
        1. Compilation architecture of TypeScript
        2. Advantages of TypeScript
          1. Superset of JavaScript
          2. Support for classes and modules
          3. Static type checking
          4. ECMAScript 6 feature support
          5. Optional typing
          6. Declaring types in TypeScript
        3. Core elements of TypeScript
          1. Declaring variables
          2. Types
          3. Classes and interfaces
            1. Defining interfaces
            2. Deriving classes and interfaces
            3. Generic classes
          4. Functions
            1. Generic functions
          5. Iterators
          6. Modules and namespaces
      2. Introduction to Angular 2
        1. Angular 2 architecture
          1. Events of component life cycle
          2. Modules
          3. Components
        2. Core properties of Angular 2 components
          1. Templates and selectors
          2. Inputs and outputs
            1. Using inputs
            2. Using outputs
          3. Directives
            1. Creating a simple Hello World directive
          4. Structural directives
          5. Attribute directive
          6. Providers
        3. Dependency injection in Angular
        4. Routing in Angular
      3. Developing a to-do application in ASP.NET Core
        1. Creating a Common project
        2. Creating a TodoServiceApp project
          1. Enabling MVC in a Web API project
          2. Installing Entity Framework
          3. Adding AppSettings to store a connection string
          4. Configuring AppSettings in the Startup class
          5. Adding data access in Web API
          6. Enabling CORS in the ASP.NET Web API
          7. Running database migration
          8. Creating a controller
        3. Creating a TodoWebApp project
          1. Configuring Angular 2 in the TodoWebApp project
          2. Dependencies
            1. Development dependencies
            2. Configuring TypeScript
            3. Configuring Gulp
          3. Adding Angular components
            1. Adding the to-do service component
            2. Adding a to-do view component
          4. Creating the main to-do page
            1. Creating a custom to-do tag helper
            2. Adding a to-do MVC controller
            3. Generating views for the TodoController action methods
            4. Developing the Create Todo component
      4. Summary
    13. 6. Exploring the WinJS Library
      1. Introduction to WinJS
        1. WinJS features
          1. JavaScript coding and language patterns
          2. Stylesheets
          3. Windows runtime access
          4. Security
          5. App model
          6. Databinding
          7. Controls
          8. Utilities
        2. Usage of WinJS
      2. Adding the WinJS library in the ASP.NET application
        1. CDN
        2. NPM
        3. NuGet
      3. Getting started with WinJS
        1. Using WinJS in the ASP.NET application
        2. Existing Windows app template in Visual Studio
      4. Exploring WinJS core fundamentals
        1. Classes and namespaces
          1. Defining classes in WinJS
          2. Deriving classes in WinJS
          3. Namespaces in WinJS
        2. Mixin
        3. Events in WinJS
        4. Databinding
          1. One time databinding
          2. One way databinding
          3. Two way databinding
          4. A databinding working model
        5. Promises
          1. Other operations of promises
            1. Chaining promises and handling errors
            2. Canceling promises
            3. Joining promises
            4. Checking promise
            5. Wrapping non-promise into promise
      5. Exploring WinJS controls and styles
        1. Adding WinJS controls
        2. Setting properties of WinJS controls
      6. Using Windows runtime features
        1. Hosted apps and accessing the camera
          1. Creating the ASP.NET core application
          2. Converting an ASP.NET application into Windows application using the Hosted app concept
      7. Summary
    14. 7. JavaScript Design Patterns
      1. Creational patterns
        1. Singleton design pattern
        2. Factory pattern
        3. Abstract factory pattern
        4. Prototype pattern
      2. Structural patterns
        1. Adapter pattern
        2. Decorator pattern
        3. Facade pattern
        4. Bridge pattern
      3. Behavioral pattern
        1. Chain of responsibility pattern
        2. Observer pattern
        3. Pub/sub pattern
        4. Promises
      4. Summary
    15. 8. Node.js for ASP.NET Developers
      1. Introduction to Node.js
        1. Request processing by the Node.js web server
        2. Comparison of Node.js with .NET
        3. NPM
      2. Installing Node.js
      3. Using Node.js with Visual Studio 2015
        1. Simple console application using Node.js
        2. Web applications with Node.js
        3. Creating blank Node.js applications
        4. Using the Express framework for web applications in Node.js
          1. Extend simple Node.js to use Express
          2. Express view engines
            1. EJS view engine
            2. Jade view engine
            3. Routing in the Express application
      4. Middleware
      5. MVC with the Express framework
        1. MVC pattern
          1. Creating a controller
          2. Creating data services
      6. Accessing the Microsoft SQL server in Node.js
        1. Reading a record from the Microsoft SQL server database
        2. Creating a record in the Microsoft SQL server database
      7. Summary
    16. 9. Using JavaScript for Large-Scale Projects
      1. Think before proceeding
      2. Developing highly scalable and maintainable applications
        1. Modularization
          1. Implementing the module pattern
          2. Modularizing JavaScript code through RequireJS
            1. Creating modules using the RequireJS API
            2. Bootstrapping RequireJS
        2. Event-driven messaging
          1. Implementing mediator pattern for communication between modules
        3. Encapsulating complex code
        4. Generating documentation
          1. Installing JSDoc3 in ASP.NET Core
            1. Adding comments
        5. Deployment optimization
      3. Summary
    17. 10. Testing and Debugging JavaScript
      1. Testing the JavaScript code
        1. Unit testing
          1. Writing unit tests
            1. Jasmine
            2. Karma
            3. Grunt
          2. Developing unit test using Jasmine, Karma, and Grunt
            1. Adding packages
            2. Adding the Grunt file
              1. Adding Karma specifications
              2. Load npm task
              3. Register task
            3. Source JavaScript file
          3. Adding unit test script file
          4. Running test task
          5. Implementing Model-View-ViewModel using Knockout and Run test
            1. Adding the Knockout package
            2. Adding ProductViewModel
            3. Add the Product view
            4. Modifying test configuration
            5. Modifying the product-testing script
      2. Debugging JavaScript
        1. Debugging options in Visual Studio 2015
          1. Debugging from Visual Studio with Internet Explorer
        2. Debugging from Visual Studio with Google Chrome
        3. Developer Tools
          1. Debugging options in Microsoft Edge
          2. Standard breakpoints
          3. Conditional breakpoints
          4. Tracepoints
          5. Event
            1. Add event tracepoint
            2. Add event breakpoints
          6. XHR
        4. Debugging TypeScript
        5. Debugger keyword supported by all browsers
      3. Summary
    18. Index

Product information

  • Title: JavaScript for .NET Developers
  • Author(s): Ovais Mehboob Ahmed Khan
  • Release date: July 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781785886461