---
title: "Javascript.new"
author: "axgle"
date: "2009-06-25T19:43:51Z"
tags: []
categories: ["Web前端"]
slug: "javascript-new"
draft: false
lastmod: "2009-06-25T20:31:39Z"
id: 415186
url: "https://axgle.iteye.com/blog/415186"
---

In firefox, make Javascript.new like Ruby.new

```java
Object.prototype['new']=function(){
    var params=[];
    var argc=arguments.length;
    for(var i=0;i<argc;i++){
        params.push('arguments['+i+']');
    }
    var code='return new this('+params.join(',')+');';
    return new Function(code).apply(this,arguments);
}

Number.new(100);//100
String.new("text");//"text"
Array.new(1,2,3);//[1,2,3]

function Person(name){
    this.name=name;
    this.toString=function(){return this.name;}
}
tom=Person.new('Tom');
joy=Person.new('Joy');
tom+" and "+joy;
```


with [ExtJS](http://extjs.com/),you can use it like this:

```java
Ext.Window.new({height:100, width:200}).show();
```