cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <table>
	<thead><tr>
    <th>Test Name</th>
    <th>Total Count</th>
    <th>Own Property Count</th>
    <th>Matches Test</th>
    <th>Prototype Property Count</th>
    <th>Matches Test</th>
  </tr></thead>
  <tbody id="result"></tbody>
</table>
            
          
!
            
              th, td {
  border-right: 1px solid black;
  padding: 0.1em 0.25em;
}
            
          
!
            
              var t1 = {a:1, b:2, c:3};
var $el = $('#result');

function Test() {};

Test.prototype = {
  test1: undefined,
  test2: function() {}
};

var test = new Test();

function fnCountProperties(o) {
  var iCountPrototype = 0;
  var iCountOwn = 0;
  var iTotal = 0;
  
  for (var prop in o) {
    if (o.hasOwnProperty(prop)) {
      iCountOwn += 1;
    } else {
      iCountPrototype += 1;
    }
  }
  
  iTotal = new Number(iCountOwn + iCountPrototype);
  iTotal.countOwn = iCountOwn;
  iTotal.countPrototype = iCountPrototype;
  
  return iTotal;
}

function fnAssertResults(sName, o, i, j) {
  var iCount = fnCountProperties(o),
      sOwnMatches = i === iCount.countOwn,
      sPrototypeMatches = j === iCount.countPrototype;
  console.log(iCount);
  $('<tr><td>' + sName + '</td><td>' + iCount + '</td><td>' + iCount.countOwn + '</td><td>' + sOwnMatches + '</td><td>' + iCount.countPrototype + '</td><td>' + sPrototypeMatches + '</td></tr>').appendTo($el);
}

fnAssertResults('{}', {}, 0, 0);
fnAssertResults("{a:1, b:2, c:3}", t1, 3, 0);
fnAssertResults('Test class', test, 0, 2);
test.test3 = 1;
fnAssertResults('Test - add own property', test, 1, 2);

// Overriding a prototype variable changes it to be on the object itself.
test.test1 = 1;
fnAssertResults('Test - override prototype variable', test, 2, 1);

Test.prototype.test4 = 2;
fnAssertResults('Add to Test.prototype', test, 2, 2);
fnAssertResults("window (will fail)", window, 0, 0);
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console