File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed
Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ Read [Code Snippets tutorial][1],
3737from [ addyosmani/timing.js] ( https://github.com/addyosmani/timing.js ) .
3838* [ time-method-call.js] ( time-method-call.js ) - measures single method call time.
3939* [ profile-method-call.js] ( profile-method-call.js ) - profiles a single method call.
40+ * [ profile-prototype-method.js] ( profile-prototype-method.js ) - profiles a single method call
41+ that is on a prototype object, not on an instance.
4042
4143### Storage measurements
4244
Original file line number Diff line number Diff line change 11{
22 "name" : " code-snippets" ,
33 "main" : " first-paint.js" ,
4- "version" : " 0.3.0 " ,
4+ "version" : " 0.3.1 " ,
55 "homepage" : " https://github.com/bahmutov/code-snippets" ,
66 "license" : " MIT" ,
77 "ignore" : [
Original file line number Diff line number Diff line change 11{
22 "name" : " code-snippets" ,
33 "description" : " Chrome DevTools code snippets " ,
4- "version" : " 0.3.0 " ,
4+ "version" : " 0.3.1 " ,
55 "author" : " Gleb Bahmutov <gleb.bahmutov@gmail.com>" ,
66 "bugs" : {
77 "url" : " https://github.com/bahmutov/code-snippets/issues"
Original file line number Diff line number Diff line change 1+ /*
2+ Almost the same as profile method call, but for wrapping methods that are on prototype
3+ function Foo() {}
4+ Foo.prototype.getName = function () { return this.name; }
5+ var foo = new Foo();
6+ foo.getName();
7+
8+ // profile getName without getting foo reference
9+ profilePrototypeCall with proto = Foo.prototype;
10+ and method name 'getName'
11+ */
12+ ( function profilePrototypeCall ( proto , methodName ) {
13+ 'use strict' ;
14+
15+ console . assert ( proto , 'cannot find prototype to profile' ) ;
16+ console . assert ( typeof methodName === 'string' , 'expected method name' ) ;
17+
18+ var originalMethod = proto [ methodName ] ;
19+ console . assert ( typeof originalMethod === 'function' , 'cannot find method ' + methodName ) ;
20+
21+ proto [ methodName ] = function ( ) {
22+ console . profile ( methodName ) ;
23+
24+ originalMethod . apply ( this , arguments ) ;
25+
26+ console . profileEnd ( methodName ) ;
27+
28+ proto [ methodName ] = originalMethod ;
29+ console . log ( 'restored the prototype method call' , methodName ) ;
30+ } ;
31+ console . log ( 'wrapped' , methodName + ' in profiling calls' ) ;
32+
33+ // some prototype and method name
34+ } ( this . Photostack . prototype , '_rotateItem' ) ) ;
You can’t perform that action at this time.
0 commit comments