LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-06-2020, 10:21 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Syntax for passing {} objects to typescript functions


https://rxjs-dev.firebaseapp.com/guide/observable
Code:
observable.subscribe({   
   next(x) { console.log('got value ' + x); },   
   error(err) { console.error('something wrong occurred: ' + err); },   
   complete() { console.log('done'); } });
As I can see they have passed functions to {} object and then passed this object as a parameter to function subscribe.

What is the function syntax for this kind of parameter accepting functions?
Does this actually mean that we are passing an object which has definitions of functions inside it as a function parameter?
Please point out the documentation.
 
Old 12-07-2020, 09:08 AM   #2
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
I don't know typescript but I believe it accepts javascript constructs as well as its typed constructs? That's certainly acceptable javascript i.e.
Code:
$ node
 > var a = function (o) { o.x(); o.y(); }
undefined
> var b = { x() { console.log ("x"); }, y() { console.log ("y"); } };
undefined
> a(b);
x
y
undefined
Maybe an interface defined to take the three functions and a function defined to take the interface?

Code:
interface SubscribeArgs { 
   next: (string)=>void, 
   error: (string)=>void, 
   complete: ()=>void
} 

interface Observable {
    subscribe: (SubscribeArgs)=>void
}
I've no idea if that is correct but: https://www.tutorialspoint.com/types...interfaces.htm
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Java passing iterators to new Objects and returning them trscookie Programming 1 03-22-2011 03:34 AM
passing C++ objects to message queues aryan1 Programming 2 08-02-2009 06:22 AM
LXer: Java Data Objects and Service Data Objects in SOA LXer Syndicated Linux News 0 01-17-2009 06:10 AM
pause displaying typescript rsashok Linux - General 2 11-16-2007 12:38 PM
about typescript AmphetaminePhreak Linux - Newbie 1 08-01-2006 03:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration