A difference between TS and C # place

Source: Internet
Author: User
Tags export class eventbus

Import {style} from '. /assets '; import {Eventbus} from‘.. /eventbus '; Import {page, rootobject} from‘.. /vm/page '; Import* As D3 from ' D3 'Import* As d3g from ' D3-shape 'Import* As SIGNALR from "@aspnet/signalr"; Export class Areamain {main:htmlmainelement; Constructor (private Stp:style, private Bus:eventbus, private vm:page) { This. main = document.createelement (' main ');  This. Bus.load ( This);        Let Uid:rootobject; if( This. vm.uidata! =undefined) {UID= This. Vm.uidata This. InitialView ( This. Main, UID);  This. SETCSS (UID)} This. conn =undefined} initialView (Parent:htmlmainelement, uid:rootobject):void{Let Div1= document.createelement (' div ') Let Div2= document.createelement (' div ') Let Div3= document.createelement (' div ')         This. Init1 (DIV1, UID) This. Init2 (Div2, UID) This. INIT3 (Div3, UID) for(varI of [Div1, Div2, Div3])    {Parent.appendchild (i)}} //#region UI componentsInit1 (Parent:htmlelement, Uid:rootobject):void {        varSVG = d3.select (parent). Append (' SVG '). attr (' Width ', ' 100% ')        varg = svg.append (' g '). attr (' Transform ', ' translate (250,10) ')        varr = g.append (' rect '). attr (' Fill ', ' skyblue '). attr (' Width ', 100). attr (' Height ', 100). attr (' Transform ', ' rotate (20,10,10) ') R.on (' Click ', () ={            if( This. conn!=undefined) {                 This. TESTKK ( This. conn)// will not be executed here! }})} init2 (Parent:htmlelement, uid:rootobject):void{Parent.setattribute (' id ', ' div2 ')        varUL = document.createelement (' ul ')) Parent.appendchild (UL) Const connection=Newsignalr. Hubconnectionbuilder (). Withurl ("Http://localhost:61866/chatHub"). build ();  This. conn =Connection Console.log (2250) Console.log ( This. Conn) Connection.on ("ReceiveMessage",function(user, message) {varencodedmsg = user + "says" +message; varLi = document.createelement ("li"); Li.textcontent=encodedmsg;        Ul.appendchild (LI);        });  This. Conn.start (). Then (x=>{console.log (x)})} Init3 (Parent:htmlelement, uid:rootobject):void {    }    //#endregion    //#region ChangeConn:signalr. hubconnection |undefined async TESTKK (connection:signalr.        Hubconnection) {await connection.start (); Await Connection.invoke ("SendMessage", ' User ', ' message '); }    //#endregionSetcss (Uid:rootobject):void {         This. Stp.create (' #div2 '). Insert (' Height ', ' 600px '). Insert (' Background-color ', ' #e8e8e9 ')         This. Stp.create (' #div2 >ul '). Insert (' List-style ', ' none ')    }}

This is my own small project code, in C # to do this is going to make sense, but TS No, see the Scarlet Letter there,

The reason I guess is because, r.on (...) Here the scope of this r is only the property Init1 method, in JS, ts method permissions are very large, it and this.conn is not in the same scope, so in the scope of R, This.conn value is only in constructor headquarters

Set in the value, do not know if there are no friends have encountered a similar situation, welcome keep abreast Discussion

A difference between TS and C # place

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.