In my current project, I am examining the JS code snippet below as part of creating a .d.ts
file:
BatchBuffer.js
var Buffer = function(size)
{
this.vertices = new ArrayBuffer(size);
/**
* View on the vertices as a Float32Array for positions
*
* @member {Float32Array}
*/
this.float32View = new Float32Array(this.vertices);
/**
* View on the vertices as a Uint32Array for uvs
*
* @member {Float32Array}
*/
this.uint32View = new Uint32Array(this.vertices);
};
module.exports = Buffer;
Buffer.prototype.destroy = function(){
this.vertices = null;
this.positions = null;
this.uvs = null;
this.colors = null;
};
After seeking guidance on Stack Overflow, it was mentioned that this code showcases a Named Function Expression (NFE)
. However, I still find the naming conventions confusing when trying to define it accurately.
Should it be defined as BatchBuffer
or simply Buffer
? And is my attempt at a correct definition accurate?
export module BatchBuffer {
export var vertices: ArrayBuffer;
export var float32View: number[];
export var uint32View: number[];
export function destroy(): void;
}
I encounter similar NFE files frequently in my project, which makes me doubt if my definitions are precise. Any advice or confirmation would be greatly appreciated.
Thank you.
Edited.
Refer to Ryan's Answer for more insights.
Most classes in my project follow a structure akin to this example:
MyClass.js
function MyClass(something)
{
/**
* Some property
*
* @member {number}
*/
this.something = something;
}
MyClass.prototype.constructor = MyClass;
module.exports = MyClass;
MyClass.prototype.hi = function ()
{
}
While I can identify this as a class, I sometimes struggle with the finer details. Recognizing them as classes suffices for my needs.