Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do WinRT types have to be sealed?

In several places (e.g. "Creating Windows Runtime Components for JavaScript, in C# and Visual Basic" on MSDN), I've seen it specified that, if you write a class in .NET that you want to use from JavaScript, then you must make it a sealed class.

This seems like an arbitrary restriction. Why can JavaScript only work with sealed classes?

like image 411
Joe White Avatar asked Sep 20 '11 21:09

Joe White


People also ask

What is WinRT used for?

C++/WinRT is an entirely standard modern C++17 language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide you with first-class access to the modern Windows API.

What is Windows Runtime net?

Windows Runtime (WinRT) is a platform-agnostic component and application architecture first introduced in Windows 8 and Windows Server 2012 in 2012.


1 Answers

Windows runtime objects exposed to JavaScript applications are sealed from a JavaScript perspective - you can't add expando properties to WinRT objects. But from C++ and C#, winrt objects can be inherited if the object supports inheritance (most Xaml classes support inheritance for instance, but most others don't).

The reason that WinRT objects are sealed from JS is to ensure that the winrt object behave the same regardless of what the app has done - if an app redefines some function property on an object, it could cause other parts of the app to misbehave.

like image 66
ReinstateMonica Larry Osterman Avatar answered Oct 07 '22 01:10

ReinstateMonica Larry Osterman