function myNew(constructor) {
var obj = {
__proto__: constructor.prototype
};
constructor.apply(obj, Array.prototype.slice.call(arguments, 1));
return obj;
}
function MyTest(i) {
this.count = i;
}
var obj1 = myNew(MyTest, 0);
console.log(obj1.count);
console.log(obj1 instanceof MyTest);
console.log(obj1 instanceof Object);
function OtherTest(i, name, value) {
this.count = i;
this.name = name;
this.value = value;
}
var obj2 = myNew(OtherTest, 0, 'myName', 'myValue');
console.log(obj2);
console.log(obj2 instanceof MyTest);
console.log(obj2 instanceof OtherTest);
分享到:
相关推荐
This lesson outlines some of the common causes that contribute to the perception of a slow server. What You Will Learn After completing this lesson, you will be able to: Describe locking ...
- **Creating a Visual Studio 2008 Project**: This section guides you through the process of setting up a new project in Visual Studio 2008, which is a powerful integrated development environment (IDE)...
book will guide you through the process, allowing you to expand your skills in Java more quickly than usual, making sense of ideas, understanding new concepts, and getting a better grasp of the ...
In summary, "JavaScript in 10 Minutes" is a comprehensive resource for intermediate to advanced JavaScript developers looking to deepen their understanding of the language's core features and advanced...
Understanding the internal architecture of SymPy is beneficial for advanced users and contributors. Key components include the core, modules, and utilities. ##### 4.4 Contributing Contributing to ...
- **Extensibility**: Lisp’s macro system allows for the creation of new language constructs, making it highly extensible and customizable. #### Getting Started with CLISP To start programming in ...
32 AM Page vi vi TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS Programming the Microsoft Way: Hungarian Notation........................55 Variable Naming ....................................