Tumgik
#powertoweightratio
papasmithcustom · 4 years
Photo
Tumblr media
Must See: A 700-Horsepower Nissan GT-R And A Porsche 911 Duke It Out On The Drag Strip @ Top Speed horsepower and torque are extremely important when it comes to drag racing but curb weight can also make a big difference. in short power-to-weight (...) https://www.topspeed.com/cars/car-news/must-see-a-700-horsepower-nissan-gt-r-and-a-porsche-911-duke-it-out-on-the-drag-strip-ar188833.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+topspeed+%28TopSpeed.com%29 #porsche911 #porsche #911 #nissangtr #nissan #gtr #powertoweight #powertoweightratio #kerbweight #curbweight #dragracing #dragracinglife #dragracinglifestyle #horsepower #torque #700bhp #700bhpclub (at Papa Smith Custom) https://www.instagram.com/p/CCMR-WPnqcT/?igshid=1icnj0r54kd7v
0 notes
obscurejavascript · 4 years
Text
Converting Class Specific Functions Into General Ones In JavaScript
If the below code blocks do not show up properly due to a recent Tumblr change. View them directly at https://obscurejavascript.tumblr.com/
Sometimes functions in classes are useful beyond just a class. Even if they do not determine their results compeletly based on the arguments passed in, they usually can be extracted. Though sometimes this functionality is too complex and modifying it is too risky, especially in legacy code. Here is a simple example, in a real work scenario the main function would be much more complicated:
class Car { constructor(name, hp, weight) { this.name = name; this.hp = hp; this.weight = weight; this.setPowerToWeightRatio(); } setPowerToWeightRatio() { this.powerRatio = Math.round((this.hp/this.weight) * 100) + '%'; } // Complex functionality that also uses setPowerToWeightRatio() here } const miata = new Car('miata', 155, 2387); console.log(miata.powerRatio); // 6%
Assuming that calculatePowerToWeightRatio cannot be modified since other parts of the code rely on it, then its functionality can still be extracted. By a collecting its this settings and then returning those:
function powerToWeightRatio(hp, weight) { const collector = { hp, weight }; Car.prototype.setPowerToWeightRatio.call(collector); return collector.powerRatio; } console.log(powerToWeightRatio(1000, 1000)); // 100% console.log(powerToWeightRatio(500, 1000)); // 50%
Notice how you do not even need an instantiated object to extract the function. Just having a reference to the class works. I am calling this using a Collector since I could find no reference to this tactic on the internet (probably because it is very niche). So by using a Collector, the setPowerToWeightRatio method can be used across the code in general without having modified the original one or having copied any code.
Finally, it is best to avoid coding in the way of the original class when possible. At the very least, instead of using built in properties it is more flexible to pass in properties. Additionally, if a value is returned instead of set internally, it will make the method much more flexible without much extra work. The above tactic is used to work with legacy code (e.g. large libraries) that you do not have time to modify in the short term.
Github Location https://github.com/Jacob-Friesen/obscurejs/blob/master/2020/collector.js
7 notes · View notes
tincanswithstrings · 8 years
Video
instagram
Did a fun bench press session with @andy.plant77 tonight hit a decent touch & go with 125kg & a 130kg with a tiny touch from Andy, felt good though considering I haven't been bench pressing heavy for a while! #scarboroughuk #personaltrainer #benchpress #strong #powertoweight #powertoweightratio #powerlifting #chestday (at Rick's Fitness and Wellbeing)
0 notes