Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TXInstance(settings) {
- this.transmit = function(data) {
- // Transmit data using settings
- }
- }
- function RXInstance(settings) {
- this.receive = function(data) {
- // Receive data using settings
- }
- }
- function Device(settings) {
- this.settings = settings;
- }
- Device.prototype.asTransmitter = function() {
- this._txInstance = new TXInstance(this.settings);
- this.transmit = function(data) {
- this._txInstance.transmit(data);
- }
- return this;
- }
- Device.prototype.asReceiver = function() {
- this._rxInstance = new RXInstance(this.settings);
- this.receive = function(data) {
- this._rxInstance.receive();
- }
- return this;
- }
- Device.prototype.asTransceiver = function() {
- this.asTransmitter(this);
- this.asReceiver(this);
- return this;
- }
- var d = new Device({foo: 'bar'});
- console.log(d);
- var tx = new Device({foo: 'bar'}).asTransmitter();
- console.log(tx);
- var rx = new Device({foo: 'bar'}).asReceiver();
- console.log(rx);
- var txrx = new Device({foo: 'bar'}).asTransceiver();
- console.log(txrx);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement