The function is not specified in Object.keys or Object.getOwnPropertyNames, but can be called

Suppose there is some javascript library object jsObj. When calling Object.keysor Object.getOwnPropertyNamesI get a list of properties like

[a,b,c,d]

But still, I can call a type function jsObj.e(). Why is the method enot part of Object.keysor Object.getOwnPropertyNames? How do they do it?

Here , it is said that Object.getOwnPropertyNamesit will also return enumerable properties. So what is the characteristic of a property like the one eabove.

I am using opentok on the server side of the SDK. Using the following code,

var OpenTok = require('opentok');
var opentok = new OpenTok(config.tokbox.apiKey, config.tokbox.secret);
console.log("opentok1", Object.getOwnPropertyNames(opentok));
prints -> // [ '_client',
  'apiKey',
  'apiSecret',
  'apiUrl',
  'startArchive',
  'stopArchive',
  'getArchive',
  'deleteArchive',
  'listArchives' ] 
console.log("opentok2", opentok.createSession);
prints -> function (...){...}
+4
source share
2

Object.e . :

var test = function() {}
test.prototype = { e: function() { return 'e'; } }
var obj = new test();
Object.keys(obj) // returns []
obj.e() // returns 'e'

- Object.keys():

Object.keys(Object.getPrototypeOf(obj))

, , .

+5

JS

:

. , for... in cycle, :

var keys = [];
for (var key in object)
    keys.push(key);

.

. .

+2

All Articles