File: example.js

package info (click to toggle)
node-class-utils 0.3.6-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 212 kB
  • sloc: javascript: 779; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 755 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var cu = require('class-utils');

// function App() {}
// Object.defineProperty(App.prototype, 'count', {
//   get: function () {
//     return Object.keys(this).length;
//   }
// });
// console.log(cu.getDescriptor(App.prototype, 'count'));

function defineProp (obj, name, fn) {
  Object.defineProperty(obj, name, {
    enumerable: true,
    configurable: true,
    get: function () {
      return fn();
    }
  });
}

function fn() {
  console.log('hey!');
  return function (msg) {
    return 'foo ' + msg;
  };
}

var one = {
  bar: function (msg) {
    return 'bar ' + msg;
  }
};
var two = {};
defineProp(one, 'foo', fn);

cu.copyDescriptor(two, one, 'foo');
cu.copyDescriptor(two, one, 'bar');

console.log(two.foo('a'))
console.log(two.bar('b'))